javascript - Node.js 流 'end' 事件未触发

标签 javascript node.js stream

下面的数据流不会触发'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/

相关文章:

javascript - 如何使用Mysql和node.js进行同步数据库查询?

javascript - Internet Explorer 显示本地存储的旧值

javascript - 语法错误: Unexpected token ILLEGAL nodes

java - Java 管道流 'stored' 的内容在哪里?

html - 使用HTML5 <audio>标记时,浏览器在页面刷新时将RST发送到shoutcast流

java - 无法将 System.out 实例正确传递给 FilterOutputStream

javascript - 如何在循环中返回多个(并行)异步函数调用的累积结果?

node.js - 在 Node.js 中加载 html 页面

javascript - 手动更新记录时不触发 Sequelize Hook

node.js - 如何使用 Angular-Cli 创建部署到 ZIP ./dist 文件夹的过程