-
-
Save calvinmetcalf/7ec2b9a45cd4db8a8a08 to your computer and use it in GitHub Desktop.
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
// In this example, I want to create a stream that pipes a file through a transform, | |
// *without* beginning to read data from the file. I want the whole pipeline to be | |
// lazy until I call read() on the end of the pipeline. | |
// | |
// Instead, the console.log() call fires unexpectedly with every line of the file. | |
var fs = require('fs'), | |
split = require('split'), | |
stream = require('stream'); | |
var dest = new stream.Transform({highWaterMark: 1}); | |
dest._transform = function(chunk, encoding, callback) { | |
console.log(chunk); | |
callback(null, chunk);//<- need to emit something | |
}; | |
var result = fs.createReadStream('./foo.txt').pipe(split()).pipe(dest); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment