
Research
Malicious Go “crypto” Module Steals Passwords and Deploys Rekoobe Backdoor
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.
A tiny wrapper around Node streams.Transform (Streams2/3) to avoid explicit subclassing noise
Inspired by Dominic Tarr's through in that it's so much easier to make a stream out of a function than it is to set up the prototype chain properly: through(function (chunk) { ... }).
Note: As 2.x.x this module starts using Streams3 instead of Stream2. To continue using a Streams2 version use npm install through2@0 to fetch the latest version of 0.x.x. More information about Streams2 vs Streams3 and recommendations see the article Why I don't use Node's core 'stream' module.
fs.createReadStream('ex.txt')
.pipe(through2(function (chunk, enc, callback) {
for (var i = 0; i < chunk.length; i++)
if (chunk[i] == 97)
chunk[i] = 122 // swap 'a' for 'z'
this.push(chunk)
callback()
}))
.pipe(fs.createWriteStream('out.txt'))
.on('finish', () => doSomethingSpecial())
Or object streams:
var all = []
fs.createReadStream('data.csv')
.pipe(csv2())
.pipe(through2.obj(function (chunk, enc, callback) {
var data = {
name : chunk[0]
, address : chunk[3]
, phone : chunk[10]
}
this.push(data)
callback()
}))
.on('data', (data) => {
all.push(data)
})
.on('end', () => {
doSomethingSpecial(all)
})
Note that through2.obj(fn) is a convenience wrapper around through2({ objectMode: true }, fn).
through2([ options, ] [ transformFunction ] [, flushFunction ])
Consult the stream.Transform documentation for the exact rules of the transformFunction (i.e. this._transform) and the optional flushFunction (i.e. this._flush).
The options argument is optional and is passed straight through to stream.Transform. So you can use objectMode:true if you are processing non-binary streams (or just use through2.obj()).
The options argument is first, unlike standard convention, because if I'm passing in an anonymous function then I'd prefer for the options argument to not get lost at the end of the call:
fs.createReadStream('/tmp/important.dat')
.pipe(through2({ objectMode: true, allowHalfOpen: false },
(chunk, enc, cb) => {
cb(null, 'wut?') // note we can use the second argument on the callback
// to provide data as an alternative to this.push('wut?')
}
)
.pipe(fs.createWriteStream('/tmp/wut.txt'))
The transformFunction must have the following signature: function (chunk, encoding, callback) {}. A minimal implementation should call the callback function to indicate that the transformation is done, even if that transformation means discarding the chunk.
To queue a new chunk, call this.push(chunk)—this can be called as many times as required before the callback() if you have multiple pieces to send on.
Alternatively, you may use callback(err, chunk) as shorthand for emitting a single chunk or an error.
If you do not provide a transformFunction then you will get a simple pass-through stream.
The optional flushFunction is provided as the last argument (2nd or 3rd, depending on whether you've supplied options) is called just prior to the stream ending. Can be used to finish up any processing that may be in progress.
fs.createReadStream('/tmp/important.dat')
.pipe(through2(
(chunk, enc, cb) => cb(null, chunk), // transform is a noop
function (cb) { // flush function
this.push('tacking on an extra buffer to the end');
cb();
}
))
.pipe(fs.createWriteStream('/tmp/wut.txt'));
through2.ctor([ options, ] transformFunction[, flushFunction ])
Instead of returning a stream.Transform instance, through2.ctor() returns a constructor for a custom Transform. This is useful when you want to use the same transform logic in multiple instances.
var FToC = through2.ctor({objectMode: true}, function (record, encoding, callback) {
if (record.temp != null && record.unit == "F") {
record.temp = ( ( record.temp - 32 ) * 5 ) / 9
record.unit = "C"
}
this.push(record)
callback()
})
// Create instances of FToC like so:
var converter = new FToC()
// Or:
var converter = FToC()
// Or specify/override options when you instantiate, if you prefer:
var converter = FToC({objectMode: true})
through2 as well as many more useful stream modules similar to this onethrough2 is Copyright (c) Rod Vagg @rvagg and additional contributors and licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.
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 25,160,965 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.

Research
An impersonated golang.org/x/crypto clone exfiltrates passwords, executes a remote shell stager, and delivers a Rekoobe backdoor on Linux.

Security News
npm rolls out a package release cooldown and scalable trusted publishing updates as ecosystem adoption of install safeguards grows.

Security News
AI agents are writing more code than ever, and that's creating new supply chain risks. Feross joins the Risky Business Podcast to break down what that means for open source security.