mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -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>
26 lines
499 B
JavaScript
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));
|