2013-10-18 41 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