Introducing through2
through2 is a module you can install with npm:
$ npm install through2 // ☛ or add -s
or you can use stream.Transform
from node core.
This is how it would look like with the newer core interface:
var Transform = require('stream').Transform // import it
// or import it from npm ↴
var Transform = require('readable-stream').Transform
// ☛ there's also a finish function (what should happen when the stream
// is done with
var toUpper = new Transform({ // ☛ need to call with new
transform: function (buf, enc, next) {
next(null, buf.toString().toUpperCase())
}
})
process.stdin
.pipe(toUpper)
.pipe(process.stdout)