Skip to content

Instantly share code, notes, and snippets.

@lxe
Last active August 29, 2015 14:12
Show Gist options
  • Save lxe/b995cb519710abb8bbc3 to your computer and use it in GitHub Desktop.
Save lxe/b995cb519710abb8bbc3 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var stream = require('stream');
var ts = new stream.Transform();
ts._transform = function(chunk, enc, cb) {
// 'chunk' is the data from the readable source
//
// 'this.push(whatever)' or callback(err, whatever) writes
// to target writeable
cb(null, chunk.toString().toUpperCase());
}
ts.on('pipe', function (src) {
src.on('end', function () {
ts.push('\n\ntrailer!');
});
});
fs.createReadStream('./stream-test.js')
.pipe(ts, {end : false})
.pipe(process.stdout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment