Created
June 4, 2014 14:55
-
-
Save nycdavid/9778158c51fe53b02266 to your computer and use it in GitHub Desktop.
Basic Streams
This file contains hidden or 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
| 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