Skip to content

Instantly share code, notes, and snippets.

@nycdavid
Created June 4, 2014 14:55
Show Gist options
  • Select an option

  • Save nycdavid/9778158c51fe53b02266 to your computer and use it in GitHub Desktop.

Select an option

Save nycdavid/9778158c51fe53b02266 to your computer and use it in GitHub Desktop.
Basic Streams
var fs = require('fs'),
path = '/path/to/sql/file'; // This represents a 4-5 gb file, way too large for a buffer in memory
// Without Streams
fs.readFile(path, 'utf8', function(err, data) { // This will fail because the size is too large for BUffer creation
if (err) throw err;
console.log(data);
});
// With Streams
fs.createReadStream(path).pipe(process.stdout); // Continuously reads the contents of the file to process stdout, minimally writes to memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment