Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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);
The result of require is a 'function()' that when invoked, will return a Readable Stream.
var streamify = require('stream-array');
The source array can contain any type as it is assumed that the receiving stream can handle it. Each element in the array will be pushed into the piped stream, without modifying the source array.
var readable = streamify(['Hello', new Buffer('World')]);
This Stream will push each element of the source array into the piped array.
readable(['1', '2', '3', os.EOL]).pipe(process.stdout);
123\n
npm install stream-array
FAQs
Pipe an Array through Node.js streams
The npm package stream-array receives a total of 118,650 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.