Skip to content

Instantly share code, notes, and snippets.

@phated
Created July 7, 2016 22:13
Show Gist options
  • Select an option

  • Save phated/10d95bb38ed104ce00bf564d3b3f9ac2 to your computer and use it in GitHub Desktop.

Select an option

Save phated/10d95bb38ed104ce00bf564d3b3f9ac2 to your computer and use it in GitHub Desktop.
Streams confusion
// This doesn't work because I use { end: false } but I need the fd
var fs = require('fs');
var outStream = fs.createWriteStream('out-file.txt');
outStream.once('finish', function() {
console.log('finish');
outStream.end();
});
var inStream = fs.createReadStream('file.txt');
inStream.pipe(outStream, { end: false });
// This works when I remove { end: false } but it closes the fd
var fs = require('fs');
var outStream = fs.createWriteStream('out-file.txt');
outStream.once('finish', function() {
console.log('finish');
outStream.end();
});
var inStream = fs.createReadStream('file.txt');
inStream.pipe(outStream);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment