使用event-stream结束处理流

3
我正在使用JSONStream读取一个大型的JSON文件,当整个流程处理完毕时我想调用一个方法。
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");
  })
);

我该怎么做呢?
2个回答

4

我使用'event-stream'来处理包含JSON的大约200KB文件,并且在使用'event-stream'时,当使用'end'事件时,出现了从未调用'end'事件的问题,但是如果我将.on('end')放置在event-stream管道之后,则一切正常!但是当我将其放在管道之前时,一切都可以正常工作!

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

,

翻译为:

{{链接1:nodejs}}, {{链接2:event-stream}}


1

已排序。将读取流保存在变量中,并在该读取流上管道化一个on('end', function)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接