Node.jsstream'结束'事件不会触发

以下数据stream不会触发“结束”事件。 'data'事件被触发,我可以看到logging到控制台的每一行数据。

var AWS = require('aws-sdk'); var ogr2ogr = require('ogr2ogr'); var JSONStream = require('JSONStream'); var S3 = new AWS.S3(); var source = S3.getObject({bucket: ..., key: ...}).createReadStream(); var stream = ogr2ogr(source).format("GeoJSON").stream() .pipe(JSONStream.parse('features.*')); stream.on('data', function(data){ console.log(data); // Correctly outputs 70 rows of data. }) stream.on('end', function(){ console.log('end'); // This code is never executed. }) stream.on('error', function(err){ console.log(err); // No errors... }) 

如果我在ogr2ogr变换之后创build了写 – >读stream,这个过程就可以工作。

看看文档: https : //nodejs.org/api/stream.html#stream_event_end

Note that the 'end' event will not fire unless the data is completely consumed. This can be done by switching into flowing mode, or by calling stream.read() repeatedly until you get to the end