2013-10-18 38 views
2

我现在在做NodeJS流的很多工作。NodeJS流 - 泄漏管道?

我发现自己需要的一件事是'漏水管'。

stream.PassThrough一样,但只在(并且只有)它没有发送它的地方才会丢弃数据。

这样的事情已经存在吗? (stream.Transform)有多少下游管道连接?

回答

3

我最终与解决方案想出了:

LeakyTransform.prototype._transform = function(chunk, encoding, done) { 
    if (this._readableState.pipesCount > 0) { 
    this.push(chunk); 
    } 
    done(); 
} 
0

直通实现_transfrom如下:

PassThrough.prototype._transform = function(chunk, encoding, cb) { 
    cb(null, chunk); 
}; 

我认为你需要可以这样实现的:

Leak.prototype._transform = function(chunk, encoding, cb) { 
}; 

即无操作

+0

谢谢,但是当'泄漏的管道'被管道输入时,它不应再泄漏。我不是在寻找'/ dev/null'。 – fadedbee