下面的数据流不会触发'end'事件。 “数据”事件被触发,我可以看到记录到控制台的每个数据行。
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 转换后创建写入 -> 读取流,则该过程有效。
最佳答案
查看文档: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 a flowing mode, or by calling stream.read() repeatedly until you get to the end
关于javascript - Node.js 流 'end' 事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35805759/