Skip to content

Instantly share code, notes, and snippets.

@nanha
Created March 13, 2013 04:08
Show Gist options
  • Save nanha/5149318 to your computer and use it in GitHub Desktop.
Save nanha/5149318 to your computer and use it in GitHub Desktop.
node.js v0.10. StreamV2. duplex stream
var stream = require('stream');
var dest = new stream.Duplex, dest2 = new stream.Duplex;
dest._read = function(size) {};
dest._write = function(chunk, encoding, cb) {
this.push(chunk.toString().toUpperCase());
cb();
};
dest2._read = function(size) {};
dest2._write = function(chunk, encoding, cb) {
var a = Buffer.concat([chunk, new Buffer("--- @We.pipe(Node).pipe('essential').pipe(You)\n")]);
this.push(a);
cb(null);
};
dest2.on('error', function() {
console.log(arguments);
});
process.stdin
.pipe(dest)
.pipe(dest2)
.pipe(process.stdout)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment