[英]End processing a stream using event-stream
我正在使用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");
})
);
我怎样才能做到这一点?
我使用'event-stream'来处理~200kB文件中包含JSONs并且在使用'event-stream'时从未调用'end'事件时遇到问题,如果我在事件流之后放了.on('end')管道。 但是当我把它放在管道之前 - 一切正常!
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();
}));
排序。 将读取流保存在变量中并在该读取流上输入on('end',function)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.