2
我现在在做NodeJS流的很多工作。NodeJS流 - 泄漏管道?
我发现自己需要的一件事是'漏水管'。
与stream.PassThrough
一样,但只在(并且只有)它没有发送它的地方才会丢弃数据。
这样的事情已经存在吗? (stream.Transform
)有多少下游管道连接?
我现在在做NodeJS流的很多工作。NodeJS流 - 泄漏管道?
我发现自己需要的一件事是'漏水管'。
与stream.PassThrough
一样,但只在(并且只有)它没有发送它的地方才会丢弃数据。
这样的事情已经存在吗? (stream.Transform
)有多少下游管道连接?
我最终与解决方案想出了:
LeakyTransform.prototype._transform = function(chunk, encoding, done) {
if (this._readableState.pipesCount > 0) {
this.push(chunk);
}
done();
}
直通实现_transfrom如下:
PassThrough.prototype._transform = function(chunk, encoding, cb) {
cb(null, chunk);
};
我认为你需要可以这样实现的:
Leak.prototype._transform = function(chunk, encoding, cb) {
};
即无操作
谢谢,但是当'泄漏的管道'被管道输入时,它不应再泄漏。我不是在寻找'/ dev/null'。 – fadedbee