如何使可写流写入无处?

10

我这里的问题是我已经设置了一条流水线,像这样。

readableStream.pipe(transformStream).pipe(writableStream);

我并不真正希望可写流把内容写到任何地方,只是想利用它来避免我的转换流缓冲区积压。如何使可写流将内容写入一个空目标?


2
如果你要忽略所有的输出,使用Transform流有什么意义呢?为什么不一开始就使用Writable流呢? - mscdex
2个回答

6

有很多方法...其中一些会崩溃节点并导致节点错误报告器崩溃...为了避免这种情况,不要在没有相应的读取器的情况下使用PassThrough,一定要调用回调函数。

// hellSpawn: 268MiB/s. RSS 298
// write2Null: 262MiB/s. RSS 138
// passThrough: 259MiB/s. RSS 2667
// noCb: 256MiB/s. RSS 2603
// fancy: 256MiB/s. RSS 106

{
      hellSpawn: (childProcess.spawn('sh', ['-c', 'cat > /dev/null'])).stdin,
      write2Null: fs.createWriteStream('/dev/null'),
      passThrough: new PassThrough(),
      noCb: new (class extends Writable {_write = () => {}})(),
      fancy: new  Writable ({write: (a,b,cb) => cb()})()
}

4

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接