gpt4 book ai didi

node.js - 如何设置可写高水位线?

转载 作者:太空宇宙 更新时间:2023-11-03 22:49:20 26 4
gpt4 key购买 nike

我在选项中发现为 readable stream 设置高水位线:fs.createReadStream(path[, options])

但找不到 writeable stream高水位线选项

那么创建可写流时如何设置呢?

最佳答案

尽管 fs.createWriteStream 上没有记录它,但 stream.Writable可以采用:highWaterMark 作为选项。

fs.createWriteStream('out', { highWaterMark: 32000 });

console.log(stream._writableState.highWaterMark); // 32000

并实际测试它是否正常工作:

const lowHWStream = fs.createWriteStream('low', { highWaterMark: 1 });
const highHWStream = fs.createWriteStream('high', { highWaterMark: 32000 });

console.log(lowHWStream.write('a')); // false
console.log(highHWStream.write('a')); // true

The return value is true if the internal buffer is less than the highWaterMark configured when the stream was created after admitting chunk. If false is returned, further attempts to write data to the stream should stop until the 'drain' event is emitted.

Checking the source code ,您可以看到传递给 createWriteStream 的选项被传递给 stream.Writable

关于node.js - 如何设置可写高水位线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55026306/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com