node.js - 传递流不发出完成事件

标签 node.js

我尝试使用 through2 通过管道传输一系列直通流模块。最后,我将在使用 Jasmine 的单元测试中使用它。

如果我理解正确,省略转换函数将返回一个传递流。直通流是 Transform应该发出 finish 事件的流,对吗?

以下示例中我缺少什么?我希望它输出 fooobar

var through = require('through2');

through()
 .pipe(through())
 .on('finish', function() { 
      console.log('fooobar'); 
 });

Node -v v0.12.2 通过2 v2.0.0

最佳答案

您正在通过管道传输的第一个流尚未结束。尝试这样的事情:

var through = require('through2');

var stream = through();
stream.pipe(through())
      .on('finish', function() { 
        console.log('fooobar'); 
      });
stream.end();

关于node.js - 传递流不发出完成事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31819990/

相关文章:

javascript - Nock 不返回设置的 header

node.js - Node.js 中 Node 静态的请求资源上不存在 'Access-Control-Allow-Origin' header

Node.js readStream 用于大文件末尾

javascript - 在 Nodejs 中将平面 JSON 数组转换为 JSON 对象

json - 在文档中查找数组中的元素

node.js - 如何修复此错误 TypeError [ERR_INVALID_CALLBACK] : Callback must be a function

Node.js 与 Google 应用引擎

node.js - 使用 NodeJS 的图像处理服务器

node.js - 每当我尝试将服务器添加到用户模型时,Sequelize 不会在直通/联结表中添加记录

node.js - async/await 函数未按正确顺序执行