目前,我正在使用NodeJS流做大量工作。
我发现自己需要的一件事是“漏水管”。
就像stream.PassThrough一样,但是如果(而且只有当)它没有发送它的位置时,它只会删除数据。
这样的东西已经存在了吗?
有没有办法找出(在stream.Transform内)有多少个下游管道连接?
发布于 2013-10-18 16:51:12
我最终想出了一个解决方案:
LeakyTransform.prototype._transform = function(chunk, encoding, done) {
if (this._readableState.pipesCount > 0) {
this.push(chunk);
}
done();
}发布于 2013-10-18 15:31:56
PassThrough实现_transfrom如下:
PassThrough.prototype._transform = function(chunk, encoding, cb) {
cb(null, chunk);
};我认为你所需要的可以这样实现:
Leak.prototype._transform = function(chunk, encoding, cb) {
};即非执行部分
https://stackoverflow.com/questions/19453108
复制相似问题