
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
stream-array
Advanced tools
The stream-array npm package allows you to create a readable stream from an array of data. This can be useful for processing data in a stream-based manner, which is often more efficient and scalable than processing data in a batch.
Create a readable stream from an array
This feature allows you to convert an array into a readable stream. The code sample demonstrates how to create a readable stream from an array of numbers and log each chunk of data as it is read from the stream.
const streamArray = require('stream-array');
const array = [1, 2, 3, 4, 5];
const readableStream = streamArray(array);
readableStream.on('data', (chunk) => {
console.log(chunk);
});
Pipe the stream to another writable stream
This feature allows you to pipe the readable stream created from an array to another writable stream. The code sample demonstrates how to create a readable stream from an array of strings and pipe it to a writable stream that logs each chunk of data.
const streamArray = require('stream-array');
const { Writable } = require('stream');
const array = ['a', 'b', 'c'];
const readableStream = streamArray(array);
const writableStream = new Writable({
write(chunk, encoding, callback) {
console.log(chunk.toString());
callback();
}
});
readableStream.pipe(writableStream);
The from2 package provides a way to create a readable stream from a variety of sources, including arrays, buffers, and iterators. It offers more flexibility compared to stream-array, which is specifically designed for arrays.
The readable-stream package is a core Node.js module that provides a standard interface for working with streams. It is more comprehensive and versatile than stream-array, supporting a wide range of stream operations beyond just converting arrays to streams.
The through2 package allows you to create transform streams, which can modify or transform the data as it passes through. While stream-array focuses on creating readable streams from arrays, through2 provides more advanced stream manipulation capabilities.
Pipe an Array through Node.js streams. This is rather useful for testing other streams.
var streamify = require('stream-array'),
os = require('os');
streamify(['1', '2', '3', os.EOL]).pipe(process.stdout);
Provide an Array to streamify which will be iterated over. Each element will dequeued and pushed into the following piped stream.
npm install stream-array
FAQs
Pipe an Array through Node.js streams
The npm package stream-array receives a total of 170,522 weekly downloads. As such, stream-array popularity was classified as popular.
We found that stream-array 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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.