Skip to content

Instantly share code, notes, and snippets.

@vermaslal
Created October 16, 2015 12:19
Show Gist options
  • Save vermaslal/36cf7a748041667ce13e to your computer and use it in GitHub Desktop.
Save vermaslal/36cf7a748041667ce13e to your computer and use it in GitHub Desktop.
virtualStream in node js
var fs = require('fs');
var stream = require('stream');
var util = require('util');
function virtualStream() {
stream.Transform.call(this);
this._readableState.objectMode = false;
this._writableState.objectMode = true;
}
util.inherits(virtualStream, stream.Transform);
//
virtualStream.prototype._transform = function (obj, encoding, cb) {
this.push(new Buffer(obj.toString().replace('replace this', 'replaced to that')));
// this.push(JSON.stringify(obj));
cb();
};
var rrs = fs.createReadStream(__dirname + '/shm.txt');
var ws = fs.createWriteStream(__dirname + '/s.txt');
rrs.pipe(new virtualStream()).pipe(ws);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment