Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
stream: fix 0 transform hwm backpressure
  • Loading branch information
ronag committed Jul 5, 2022
commit 446aba69a37e65932cce2878c3edd47619595d3c
13 changes: 10 additions & 3 deletions lib/internal/streams/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,15 @@ function Transform(options) {
if (!(this instanceof Transform))
return new Transform(options);

if (options && options.highWaterMark != null) {
options = {
...options,
highWaterMark: null,
readableHighWaterMark: Math.max(1, options.highWaterMark),
writableHighWaterMark: 0
}
}

Duplex.call(this, options);

// We have implemented the _read method, and done the other things
Expand Down Expand Up @@ -164,9 +173,7 @@ Transform.prototype._write = function(chunk, encoding, callback) {
if (
wState.ended || // Backwards compat.
length === rState.length || // Backwards compat.
rState.length < rState.highWaterMark ||
rState.highWaterMark === 0 ||
rState.length === 0
rState.length < rState.highWaterMark
) {
callback();
} else {
Expand Down
3 changes: 2 additions & 1 deletion test/parallel/test-stream-passthrough-drain.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict';
const common = require('../common');
const assert = require('assert')
const { PassThrough } = require('stream');

const pt = new PassThrough({ highWaterMark: 0 });
pt.on('drain', common.mustCall());
pt.write('hello');
assert(!pt.write('hello1'));
pt.read();