Skip to content

Instantly share code, notes, and snippets.

@mvolkmann
Created April 12, 2013 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvolkmann/5375344 to your computer and use it in GitHub Desktop.
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 ...
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