NodeJSstream – 漏pipe?
目前我正在使用NodeJSstream进行大量的工作。
我发现自己需要的一件事是“漏水pipe道”。
就像stream.PassThrough
一样,但是如果(而且只是)没有发送数据的话,它只会丢弃数据。
这样的事情已经存在吗?
有没有办法找出(在一个stream.Transform
)有多less下游pipe道连接?
我终于想出了一个解决scheme:
LeakyTransform.prototype._transform = function(chunk, encoding, done) { if (this._readableState.pipesCount > 0) { this.push(chunk); } done(); }
PassThrough实现_transfrom如下:
PassThrough.prototype._transform = function(chunk, encoding, cb) { cb(null, chunk); };
我认为你需要的可以这样实现:
Leak.prototype._transform = function(chunk, encoding, cb) { };
即没有操作