Skip to content

Instantly share code, notes, and snippets.

@czzarr
Last active December 19, 2015 05:09
Show Gist options
  • Save czzarr/5902531 to your computer and use it in GitHub Desktop.
Save czzarr/5902531 to your computer and use it in GitHub Desktop.
Transform a Readable objects stream into a buffer stream with a Transform stream.
var stream = require('stream');
var through = stream.Transform();
through._writableState.objectMode = true;
through._transform = function (chunk, encoding, done) {
this.push(JSON.stringify(chunk));
this.push('\n');
done();
};
var Readable = ream.Readable;
var rs = Readable({ objectMode: true });
var c = 97 - 1;
rs._read = function () {
if (c >= 'z'.charCodeAt(0)) return rs.push(null);
setTimeout(function () {
rs.push({ ops: String.fromCharCode(++c)});
}, 100);
};
rs.pipe(through).pipe(process.stdout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment