使用事件stream结束处理stream

我正在阅读使用JSONStream一个大的JSON文件,我想在整个stream处理时调用一个方法。

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"); }) ); 

我怎样才能做到这一点?

我使用'事件stream'处理约200kB文件包含JSONs里面,并得到'结束'的问题事件从来没有被调用时使用'事件stream',如果我.on('结束')事件stream后pipe道。 但是当我把它放在pipe道之前 – 一切正常!

 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(); })); 

nodejs , 事件stream

sorting。 将读取的stream保存在一个variables中,并在该读取stream上传递一个on('end',function)。