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-each
Advanced tools
The stream-each package is a utility that allows for iterating over the data in a readable stream one chunk at a time. It works by providing a function that is called for each chunk of data read from the stream, and a callback that is called when there is no more data or an error occurs.
Iterating over stream data
This feature allows you to process data from a stream chunk by chunk. The provided code sample demonstrates how to read from a file stream and log each chunk of data to the console.
const each = require('stream-each');
const fs = require('fs');
const stream = fs.createReadStream('/path/to/file.txt');
each(stream, function (chunk, next) {
console.log(chunk.toString());
next();
}, function (err) {
if (err) throw err;
console.log('Finished reading the stream.');
});
Through2 is a tiny wrapper around Node streams.Transform, making it easier to create transform streams. It is similar to stream-each in that it allows processing of stream data, but it focuses on transforming the data rather than just iterating over it.
Pump is a module that pipes streams together and destroys all of them if one of them closes. It is similar to stream-each in that it deals with stream control flow, but it is more about managing the lifecycle of multiple streams rather than iterating over a single stream's data.
Mississippi is a collection of useful stream utility modules for things like piping streams together and handling errors. It includes both through2 and pump, among others, and provides a more comprehensive toolkit compared to stream-each's focused iteration functionality.
Iterate all the data in a stream
npm install stream-each
var each = require('stream-each')
each(stream, function (data, next) {
console.log('data from stream', data)
// when ready to consume next chunk
next()
}, function (err) {
console.log('no more data')
})
each(stream, iterator, cb)
Iterate the data in the stream by calling the iterator function with (data, next)
where data is a data chunk and next is a callback. Call next when you are ready to
consume the next chunk. Optionally you can call next with an error to destroy the stream
When the stream ends/errors the callback is called if provided
MIT
stream-each
is part of the mississippi stream utility collection which includes more useful stream modules similar to this one.
FAQs
Iterate all the data in a stream
The npm package stream-each receives a total of 5,666,031 weekly downloads. As such, stream-each popularity was classified as popular.
We found that stream-each demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 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
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.