Created
October 16, 2015 12:19
-
-
Save vermaslal/36cf7a748041667ce13e to your computer and use it in GitHub Desktop.
virtualStream in node js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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