Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7612574

Browse filesBrowse files
mcollinaaddaleax
authored andcommitted
stream: make _read() be called indefinitely if the user wants so
Fixes: #26097 PR-URL: #26135 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 8584068 commit 7612574
Copy full SHA for 7612574

File tree

Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+35
-0
lines changed
Open diff view settings
Collapse file

‎lib/_stream_readable.js‎

Copy file name to clipboardExpand all lines: lib/_stream_readable.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,7 @@ Readable.prototype.read = function(n) {
494494
};
495495

496496
function onEofChunk(stream, state) {
497+
debug('onEofChunk');
497498
if (state.ended) return;
498499
if (state.decoder) {
499500
var chunk = state.decoder.end();
@@ -524,6 +525,7 @@ function onEofChunk(stream, state) {
524525
// a nextTick recursion warning, but that's not so bad.
525526
function emitReadable(stream) {
526527
var state = stream._readableState;
528+
debug('emitReadable', state.needReadable, state.emittedReadable);
527529
state.needReadable = false;
528530
if (!state.emittedReadable) {
529531
debug('emitReadable', state.flowing);
@@ -537,6 +539,7 @@ function emitReadable_(stream) {
537539
debug('emitReadable_', state.destroyed, state.length, state.ended);
538540
if (!state.destroyed && (state.length || state.ended)) {
539541
stream.emit('readable');
542+
state.emittedReadable = false;
540543
}
541544

542545
// The stream needs another readable event if
Collapse file
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const assert = require('assert');
5+
const { Readable } = require('stream');
6+
7+
const buf = Buffer.alloc(8192);
8+
9+
const readable = new Readable({
10+
read: common.mustCall(function() {
11+
this.push(buf);
12+
}, 31)
13+
});
14+
15+
let i = 0;
16+
17+
readable.on('readable', common.mustCall(function() {
18+
if (i++ === 10) {
19+
// We will just terminate now.
20+
process.removeAllListeners('readable');
21+
return;
22+
}
23+
24+
const data = readable.read();
25+
// TODO(mcollina): there is something odd in the highWaterMark logic
26+
// investigate.
27+
if (i === 1) {
28+
assert.strictEqual(data.length, 8192 * 2);
29+
} else {
30+
assert.strictEqual(data.length, 8192 * 3);
31+
}
32+
}, 11));

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.