Created
April 28, 2012 06:04
-
-
Save max-mapper/2516455 to your computer and use it in GitHub Desktop.
fs stream backpressure example
This file contains 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'), | |
stream = fs.createWriteStream('blah.txt', { flags: 'w', encoding: 'utf-8' }), | |
i = 0, | |
status; | |
stream.on('open', write) | |
function write() { | |
if (i > 100) return stream.end() | |
console.log(i) | |
status = stream.write('writing' + i) | |
i++ | |
while (status) write() | |
} | |
stream.on('drain', write) | |
stream.on('error', function(err) { | |
console.log("stream error", err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment