【发布时间】:2016-05-13 07:05:52
【问题描述】:
我想知道是否可以使用可写流 (require('stream').Writable) 作为事件发射器。
例如,
var jsonData = [];
var strm = new stream.Writable({
write: function(chunk, encoding, next) {
jsonData.push(chunk.toString());
next();
}
});
strm.on('foo',function(msg){
console.log(msg); //doesn't get called
});
strm.emit('foo','bar'); //this doesn't seem to do anything
我认为可读/可写流是事件发射器,但我似乎不能真正以这种方式使用它们?还想知道我是否通过写入 Writable 对象/流之外的数组来正确使用 Writable。
【问题讨论】:
标签: node.js pipe jsonstream