Created
May 18, 2013 09:11
-
-
Save kerphi/5603809 to your computer and use it in GitHub Desktop.
basic usage of nodejs stream v2
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
# command called: | |
# ./streamv2writer.js | ./streamv2reader.js | |
# generates: | |
................................................. | |
end of 50 chunks | |
end of stdin 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
#!/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'); | |
}); |
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
#!/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