Files
node/test/parallel/test-stream-readable-readable-one.js
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

21 lines
460 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const { Readable } = require('stream');
// Read one buffer at a time and don't waste cycles allocating
// and copying into a new larger buffer.
{
const r = new Readable({
read() {}
});
const buffers = [Buffer.allocUnsafe(5), Buffer.allocUnsafe(10)];
for (const buf of buffers) {
r.push(buf);
}
for (const buf of buffers) {
assert.strictEqual(r.read(), buf);
}
}