Files
node/test/parallel/test-stream-readable-infinite-read.js
T
Robert Nagy fadb214d95 stream: readable read one buffer at a time
Instead of wasting cycles concatenating buffers, just return each
one by one.

Similar (but not exact) old behavior can be achieved by using
`readable.read(readable.readableLength)` instead of
`readable.read()`. In some edge cases it might be necessary
to do a `readable.read(0)` first.

PR: https://github.com/nodejs/node/pull/60441
PR-URL: https://github.com/nodejs/node/pull/60441
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2026-01-21 08:29:40 +00:00

26 lines
499 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const { Readable } = require('stream');
const buf = Buffer.alloc(8192);
const readable = new Readable({
highWaterMark: 16 * 1024,
read: common.mustCall(function() {
this.push(buf);
}, 12)
});
let i = 0;
readable.on('readable', common.mustCall(function() {
if (i++ === 10) {
readable.removeAllListeners('readable');
return;
}
assert.strictEqual(readable.read().length, 8192);
}, 11));