Created
June 26, 2016 18:33
-
-
Save keevitaja/247f814289929b89ae169f18b4e53d10 to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
/* | |
data.txt: | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
*/ | |
const fs = require('fs'); | |
const Transformer = require('stream').Transform; | |
let stream = fs.createReadStream('data.txt'); | |
let gt3 = (chunk)=> { | |
let partial = []; | |
let str = chunk.toString().split(/\n/); | |
for (let i = 0, len = str.length; i < len; i++) { | |
if (str[i] > 3) { | |
partial.push(str[i]); | |
} | |
} | |
return new Buffer(partial.join('\n')); | |
}; | |
class Input extends Transformer { | |
_transform(chunk, encoding) { | |
this.push(gt3(chunk)); | |
} | |
} | |
const input = new Input(); | |
stream.pipe(input); | |
input.on('data', (chunk)=> { | |
console.log(chunk.toString()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment