Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
base64-stream
Advanced tools
Contains new Node.js v0.10 style stream classes for encoding / decoding Base64 data
The base64-stream npm package provides a streaming interface for encoding and decoding data in base64 format. It is particularly useful for handling large amounts of data that need to be processed in chunks, such as files or network streams.
Base64 Encoding
This feature allows you to encode a stream of data into base64 format. In this example, the contents of 'input.txt' are read, encoded in base64, and then written to 'output.txt'.
const fs = require('fs');
const base64 = require('base64-stream');
fs.createReadStream('input.txt')
.pipe(base64.encode())
.pipe(fs.createWriteStream('output.txt'));
Base64 Decoding
This feature allows you to decode a base64-encoded stream of data. In this example, the contents of 'input.txt' are read, decoded from base64, and then written to 'output.txt'.
const fs = require('fs');
const base64 = require('base64-stream');
fs.createReadStream('input.txt')
.pipe(base64.decode())
.pipe(fs.createWriteStream('output.txt'));
The base64-js package provides utilities for encoding and decoding base64 strings. Unlike base64-stream, it does not offer a streaming interface and is more suited for smaller data sizes that can be handled in memory.
The base64url package is designed for encoding and decoding base64 URL-safe strings. It is useful for web applications where URL-safe encoding is required. However, it does not provide a streaming interface like base64-stream.
The node-base64-image package allows you to encode and decode images to and from base64 strings. It is specialized for image data and does not offer a general-purpose streaming interface like base64-stream.
While Node.js has built-in support for Base64 data, it does not come with the ability to encode / decode data in a stream.
This library contains a streaming Base64 encoder and a streaming Base64 decoder for use with Node.js. These classes are written using the Node.js stream interfaces and are well covered with unit tests.
To install base64-stream
npm install base64-stream
This example encodes an image and pipes it to stdout.
var http = require('http');
var {Base64Encode} = require('base64-stream');
var img = 'http://farm3.staticflickr.com/2433/3973241798_86ddfa642b_o.jpg';
http.get(img, function(res) {
if (res.statusCode === 200)
res.pipe(new Base64Encode()).pipe(process.stdout);
});
This example takes in Base64 encoded data on stdin, decodes it, an pipes it to stdout.
var {Base64Encode} = require('base64-stream');
process.stdin.pipe(new Base64Encode()).pipe(process.stdout);
Base64Encode
can take an optional object {lineLength: number, prefix: string}
The prefix is useful for prepending for example data:image/png;base64,
to make a base64 URL.
This example proxies an image url, and send the base64 string in response.
app.get('/i/*', function(req, res){ // using express for example
fetch(req.params[0]) // using node-fetch
.then(r=>r.body.pipe(new Base64Encode({prefix:`data:${r.headers.get('content-type')};base64,`})).pipe(res))
.catch(console.error);
});
This module currently requires Node 6.0.0 or higher.
To run the unit tests
npm test
MIT
FAQs
Contains new Node.js v0.10 style stream classes for encoding / decoding Base64 data
The npm package base64-stream receives a total of 442,098 weekly downloads. As such, base64-stream popularity was classified as popular.
We found that base64-stream demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.