我正在使用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");
})
);我该怎么做呢?
发布于 2013-02-05 21:28:20
已排序。将读取流保存在一个变量中,并在该读取流上传递一个on('end',function)。
发布于 2014-05-29 21:42:38
我使用' event-stream‘来处理包含JSON的大约200KB的文件,如果我把.on( 'end’)放在事件流管道后面,当我使用' Event -stream‘时,当’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();
}));nodejs,event-stream
https://stackoverflow.com/questions/13419130
复制相似问题