diff --git a/lib/internal/streams/writable.js b/lib/internal/streams/writable.js index 38f1cbadd39d1d..7847469e9e7336 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..b6200ec23e530a 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']) + })) +}