Skip to content

Instantly share code, notes, and snippets.

@calvinmetcalf
Forked from jcoglan/lazy_stream.js
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calvinmetcalf/cafc789b3440e21ea28c to your computer and use it in GitHub Desktop.
Save calvinmetcalf/cafc789b3440e21ea28c to your computer and use it in GitHub Desktop.
// 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.
var fs = require('fs'),
stream = require('stream');
var dest = new stream.Transform({highWaterMark:0});
dest._transform = function(chunk, encoding, callback) {
console.log(chunk);
};
var result = fs.createReadStream('./foo.txt').pipe(dest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment