Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
stream-browserify
Advanced tools
The stream-browserify npm package is a browser-compatible version of Node.js's core stream module. It allows developers to use stream-based operations in browser environments, similar to how they would in Node.js. This includes the ability to create readable, writable, duplex, and transform streams, which can be used for handling data in a more efficient and modular way.
Creating a Readable Stream
This code sample demonstrates how to create a readable stream that emits data from an array. Each chunk of data is pushed to the stream and logged to the console when the 'data' event is emitted.
const Stream = require('stream-browserify');
let data = ['stream', 'browserify'];
let readable = Stream.Readable({
read(size) {
if (data.length === 0) this.push(null);
else this.push(data.shift());
}
});
readable.on('data', (chunk) => {
console.log(chunk.toString());
});
Creating a Writable Stream
This code sample shows how to create a writable stream that logs any data written to it to the console.
const Stream = require('stream-browserify');
let writable = new Stream.Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString());
callback();
}
});
writable.write('Hello, world!');
Piping Streams
This example demonstrates how to pipe data from a readable stream directly into a writable stream. The data from the readable stream is logged to the console as it's written to the writable stream.
const Stream = require('stream-browserify');
let readable = Stream.Readable.from(['stream', 'browserify']);
let writable = new Stream.Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString());
callback();
}
});
readable.pipe(writable);
Transform Stream
This code sample illustrates how to create a transform stream that converts any input data to uppercase. The transform stream is piped from stdin and then piped to stdout, effectively creating a stream that uppercases input from the command line.
const Stream = require('stream-browserify');
let transform = new Stream.Transform({
transform(chunk, encoding, callback) {
this.push(chunk.toString().toUpperCase());
callback();
}
});
process.stdin.pipe(transform).pipe(process.stdout);
The readable-stream package is a mirror of the stream module from Node.js core, which is specifically maintained for compatibility with different Node.js versions. It provides the same API as stream-browserify but is more focused on Node.js environments rather than the browser.
Through2 is a tiny wrapper around Node.js streams.Transform that makes it easier to create transform streams. It is similar to stream-browserify's transform stream functionality but with a simpler API for creating transform streams.
Highland.js manages synchronous and asynchronous code easily, using nothing more than standard JavaScript and Node-like streams. While stream-browserify aims to replicate Node's stream module in the browser, Highland.js provides higher-level stream operations and utilities, making it more powerful for complex stream processing tasks.
the stream module from node core, for browsers!
This module uses readable-stream
, with additions for compatibility with npm packages that use old Node.js stream APIs.
You usually do not have to install stream-browserify
yourself! If your code runs in Node.js, stream
is built in, or readable-stream
can be used. If your code runs in the browser, bundlers like browserify also include the stream-browserify
module.
But if none of those apply, with npm do:
npm install stream-browserify
Consult the node core documentation on streams.
Cross-browser testing generously provided by Sauce Labs.
3.0.0
readable-stream
3. For breaking changes, see the readable-stream notes.FAQs
the stream module from node core for browsers
The npm package stream-browserify receives a total of 11,155,583 weekly downloads. As such, stream-browserify popularity was classified as popular.
We found that stream-browserify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 40 open source maintainers 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
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.