Skip to content

Instantly share code, notes, and snippets.

@jcoglan
Last active August 29, 2015 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jcoglan/46ee10d1a33e223bfd3f to your computer and use it in GitHub Desktop.
Save jcoglan/46ee10d1a33e223bfd3f 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 with every line of the file.
var fs = require('fs'),
split = require('split'),
stream = require('stream');
var dest = new stream.Transform();
dest._transform = function(chunk, encoding, callback) {
console.log(chunk);
callback();
};
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