Skip to content

Instantly share code, notes, and snippets.

@kerphi
Created May 18, 2013 09:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerphi/5603809 to your computer and use it in GitHub Desktop.
Save kerphi/5603809 to your computer and use it in GitHub Desktop.
basic usage of nodejs stream v2
# command called:
# ./streamv2writer.js | ./streamv2reader.js
# generates:
.................................................
end of 50 chunks
end of stdin stream
#!/usr/bin/env node
var nbchunk = 0;
process.stdin.on('readable', function () {
var chunk = process.stdin.read();
if (chunk) {
process.stdout.write(chunk);
nbchunk++;
} else {
process.stdout.write('end of ' + nbchunk + ' chunks\n');
}
});
process.stdin.on('end', function () {
process.stdout.write('end of stdin stream\n');
});
#!/usr/bin/env node
setInterval(function () {
process.stdout.write('.');
}, 100);
setTimeout(function () {
process.stdout.write('\n');
process.exit(0);
}, 5000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment