Skip to content

Commit 4b0e076

Browse files
committed
fixup! stream: readable read one buffer at a time
1 parent 01a9ec9 commit 4b0e076

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

test/parallel/test-stream-readable-needReadable.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,11 @@ const asyncReadable = new Readable({
3232
});
3333

3434
asyncReadable.on('readable', common.mustCall(() => {
35-
if (asyncReadable.read() !== null) {
36-
// After each read(), the buffer is empty.
37-
// If the stream doesn't end now,
38-
// then we need to notify the reader on future changes.
39-
assert.strictEqual(asyncReadable._readableState.needReadable, true);
35+
while (asyncReadable.read() !== null) {
4036
}
37+
// If the stream doesn't end now,
38+
// then we need to notify the reader on future changes.
39+
assert.strictEqual(asyncReadable._readableState.needReadable || asyncReadable._readableState.ended, true);
4140
}, 2));
4241

4342
process.nextTick(common.mustCall(() => {

test/parallel/test-webstreams-pipeline.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const http = require('http');
126126
});
127127

128128
pipeline(r, ws, common.mustSucceed(() => {
129-
assert.deepStrictEqual(values, ['helloworld']);
129+
assert.deepStrictEqual(values, ['hello', 'world']);
130130
}));
131131

132132
r.push('hello');
@@ -181,7 +181,7 @@ const http = require('http');
181181
});
182182

183183
pipeline(rs, t, ws, common.mustSucceed(() => {
184-
assert.deepStrictEqual(values, ['HELLOWORLD']);
184+
assert.deepStrictEqual(values, ['HELLO', 'WORLD']);
185185
}));
186186

187187
c.enqueue('hello');

test/parallel/test-zlib-flush-write-sync-interleaved.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ for (const chunk of ['abc', 'def', 'ghi']) {
1919
compress.write(chunk, common.mustCall(() => events.push({ written: chunk })));
2020
compress.flush(Z_PARTIAL_FLUSH, common.mustCall(() => {
2121
events.push('flushed');
22-
const chunk = compress.read();
23-
if (chunk !== null)
22+
while (true) {
23+
const chunk = compress.read();
24+
if (chunk === null) break;
2425
compressedChunks.push(chunk);
26+
}
2527
}));
2628
}
2729

@@ -36,7 +38,13 @@ function writeToDecompress() {
3638
const chunk = compressedChunks.shift();
3739
if (chunk === undefined) return decompress.end();
3840
decompress.write(chunk, common.mustCall(() => {
39-
events.push({ read: decompress.read() });
41+
let read = '';
42+
while (true) {
43+
const x = decompress.read();
44+
if (x == null) break;
45+
read += x;
46+
}
47+
if (read) events.push({ read });
4048
writeToDecompress();
4149
}));
4250
}

0 commit comments

Comments
 (0)