mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
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>
21 lines
460 B
JavaScript
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);
|
|
}
|
|
}
|