Reading txt File in chunk in nodeJs using stream (updated : added pause and resume)

var fs = require('fs');

var stream = fs.createReadStream('data.json');


//stream.pause(); To pause the streaming
//stream.resume(); To resume the streaming


stream.on('data', function (chunk) {


console.log('-----------------START----------------');
console.log(chunk.toString());
console.log('----------------FINISH----------------');

});


stream.on('data', function (chunk) {

console.log('CHUNK LENGTH WAS: ' + chunk.length);

});

stream.on('end', function () {

console.log('----------------END OF THE FILE----------------');

});

No comments:

Post a Comment