I found in options
to set the highwatermark for readable stream:
fs.createReadStream(path[, options])
but cannot find highwatermark options
for writeable stream
So how to set it when creating a writeable stream?
Even though it's not documented on fs.createWriteStream
, a stream.Writable
can take: highWaterMark
as an option.
fs.createWriteStream('out', { highWaterMark: 32000 });
console.log(stream._writableState.highWaterMark); // 32000
And to actually test that it is working:
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, you can see that the options you pass to createWriteStream
are passed to stream.Writable
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With