Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}));
}));
}));