pipe for command line.
sample.js
var textpipe = require('textpipe');
var index = 0;
textpipe.eachLine(function(line) {
// call by each line
console.log(index, line);
index++;
},
function() {
// called on end
console.log('-- end --');
});
data.txt
aaa
bbb
ccc
run
cat data.txt | node sample.js
output
0 'aaa'
1 'bbb'
2 'ccc'
-- end --
required
eachLineCallback has a string argument.
like this:
function(line) {
console.log(line);
}
optional
It does not have arguments.
required
endCallback has a string argument.
like this:
function(allText) {
console.log(allText);
}