Skip to content

Instantly share code, notes, and snippets.

@reportbase
Last active November 18, 2015 06:06
Show Gist options
  • Save reportbase/f6ace8977fe6adc3f4b6 to your computer and use it in GitHub Desktop.
Save reportbase/f6ace8977fe6adc3f4b6 to your computer and use it in GitHub Desktop.
var readable = fs.createReadStream('data');
readable.setEncoding('utf8');
readable
.on('data', function (data) { console.log('Data!', data); })
.on('error', function (err) { console.error('Error', err); })
.on('end', function () { console.log('All done!'); });
###
var readable = fs.createReadStream('a.txt'),
writable = fs.createWriteStream('b.txt');
readable.pipe(writable)
.on('finish', function () { writable.write('an extra line'); });
###
var fs = require("fs");
var split = require("split");
var args = process.argv.slice(2);
var lines = "";
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(a)
{
lines += a;
});
process.stdin.on('end', function()
{
lines = lines.split("\n");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment