Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
A tiny wrapper around Node streams2 Transform to avoid explicit subclassing noise
The through2 npm package is a thin wrapper around Node.js streams.Transform (a standard Node.js API) that makes it easier to create transform streams. It is designed to work with streams in object mode or non-object mode, allowing for simple function-based stream transformation. This package is particularly useful when you need to create a custom stream that modifies or transforms data as it passes through the stream pipeline.
Simple Transform
This feature allows you to create a simple transform stream that converts input data to uppercase. The code sample demonstrates how to use through2 to create a stream that reads from stdin, transforms the data, and writes to stdout.
const through2 = require('through2');
const stream = through2(function(chunk, enc, callback) {
this.push(chunk.toString().toUpperCase());
callback();
});
process.stdin.pipe(stream).pipe(process.stdout);
Object Mode Transform
This feature allows you to work with streams in object mode, where the stream chunks are JavaScript objects. The code sample shows how to create a transform stream that modifies properties of objects and how to use it with a readable stream of objects.
const through2 = require('through2').obj;
const stream = through2(function(obj, enc, callback) {
obj.key = obj.key.toUpperCase();
this.push(obj);
callback();
});
// Usage with an array of objects
const objects = [{ key: 'value' }, { key: 'data' }];
const objectStream = require('stream').Readable.from(objects);
objectStream.pipe(stream).on('data', (transformedObj) => console.log(transformedObj));
Flush Function
This feature allows you to perform an action when the stream is ending, just before it finishes. The code sample demonstrates how to append a message to the stream output right before the stream ends.
const through2 = require('through2');
const stream = through2(function(chunk, enc, callback) {
this.push(chunk);
callback();
}, function(callback) {
// This function is called before the stream is finished
this.push('Stream is ending!');
callback();
});
process.stdin.pipe(stream).pipe(process.stdout);
The 'through' package provides a simple way to create a readable-writable stream. It is similar to through2 but does not support object mode by default and has a less modern API.
The 'stream-transform' package is part of the Node.js CSV project and provides a standard transform stream with a simpler API for synchronous operations. It is specifically designed for CSV data transformation and is less generic compared to through2.
The 'pumpify' package combines an array of streams into a single duplex stream using pump and duplexify. It is similar to through2 in that it deals with stream transformation but focuses on combining streams rather than creating individual transform streams.
FAQs
A tiny wrapper around Node.js streams.Transform (Streams2/3) to avoid explicit subclassing noise
The npm package through2 receives a total of 30,355,826 weekly downloads. As such, through2 popularity was classified as popular.
We found that through2 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.