diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 9f6fa4936dca62..268b54b964a835 100644 --- a/lib/internal/streams/writable.js +++ b/lib/internal/streams/writable.js @@ -565,7 +565,7 @@ function writeOrBuffer(stream, state, chunk, encoding, callback) { state[kState] &= ~kSync; } - const ret = state.length < state.highWaterMark; + const ret = state.length < state.highWaterMark || state.length === 0; if (!ret) { state[kState] |= kNeedDrain; diff --git a/test/parallel/test-streams-highwatermark.js b/test/parallel/test-streams-highwatermark.js index 7018c5bf29ce08..978a53913bd52f 100644 --- a/test/parallel/test-streams-highwatermark.js +++ b/test/parallel/test-streams-highwatermark.js @@ -85,3 +85,27 @@ const { inspect } = require('util'); hwm, })); } + +{ + const res = []; + const r = new stream.Readable({ + read() {}, + }); + const w = new stream.Writable({ + highWaterMark: 0, + write(chunk, encoding, callback) { + res.push(chunk.toString()); + callback(); + }, + }); + + r.pipe(w); + r.push('a'); + r.push('b'); + r.push('c'); + r.push(null); + + r.on('end', common.mustCall(() => { + assert.deepStrictEqual(res, ['a', 'b', 'c']); + })); +}