I am reading a large JSON file using JSONStream and I want to call a method when the whole stream is processed.
var JSONStream = require('JSONStream'), es = require('event-stream');
es.pipeline(
fs.createReadStream('file.json'),
JSONStream.parse(['features', true]),
es.map(function (data) {
console.log("Added data");
})
);
How can I do that?
I used 'event-stream' for processing of ~200kB files contain JSONs inside and got the issue when 'end' Event was never called when using 'event-stream', if I put .on('end') after event-stream pipes. But when I put it Before pipes - everything works just ok!
stream.on('end',function () {
console.log("This is the End, my friend");
}).on('error',function (err) {
console.error(err);
}).pipe(es.split())
.pipe(es.map(function (line, cb) {
//Do anything you want here with JSON of line
return cb();
}));
Sorted. Save the read stream in a variable and pipe an on('end', function) on that read stream.