Created
April 12, 2013 21:39
-
-
Save mvolkmann/5375344 to your computer and use it in GitHub Desktop.
An example of how I would write code to read from a new Node.js stream ...
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
stream.on('readable', function () { | |
var data; | |
while (true) { | |
data = stream.read(); | |
if (data === null) break; | |
// use the data | |
} | |
}); | |
stream.on('end', function () { | |
// we are done | |
}); | |
stream.on('error', function (err) { | |
// handle error | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment