Skip to content

Commit

Permalink
stream: fix Transform with hwm 0 regression
Browse files Browse the repository at this point in the history
  • Loading branch information
kanongil committed Jul 1, 2022
1 parent 736a7d8 commit b8a1698
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/streams/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,12 @@ Transform.prototype._write = function(chunk, encoding, callback) {
wState.ended || // Backwards compat.
length === rState.length || // Backwards compat.
rState.length < rState.highWaterMark ||
rState.highWaterMark === 0 ||
rState.length === 0
) {
callback();
} else {
this[kCallback] = callback;
rState.needReadable = true; // Always call _read() on the next read() call
}
});
};
Expand Down
28 changes: 28 additions & 0 deletions test/parallel/test-stream-transform-hwm0.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const common = require('../common');
const assert = require('assert');
const { Transform } = require('stream');

const t = new Transform({
objectMode: true, highWaterMark: 0,
transform(chunk, enc, callback) {
process.nextTick(() => callback(null, chunk, enc));
}
});

assert.strictEqual(t.write(1), false);
t.on('drain', common.mustCall(() => {
assert.strictEqual(t.write(2), false);
t.end();
}));

t.once('readable', common.mustCall(() => {
assert.strictEqual(t.read(), 1);
setImmediate(common.mustCall(() => {
assert.strictEqual(t.read(), null);
t.once('readable', common.mustCall(() => {
assert.strictEqual(t.read(), 2);
}));
}));
}));

0 comments on commit b8a1698

Please sign in to comment.