stream: copy SAB-backed chunks in iter consumers

Ensure bytes() copies single chunks backed by SharedArrayBuffer so
arrayBuffer() and arrayBufferSync() return ArrayBuffer instances as
specified.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/64382
Fixes: https://github.com/nodejs/node/issues/64381
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mattias Buelens <mattias@buelens.com>
This commit is contained in:
Trivikram Kamat authored and Antoine du Hamel committed 2026-08-06 15:35:02 +02:00
1 parent 7fd5f66376
commit d4dfb66bdf
3 files changed
+22 -17

No files matched your search

@@ -52,6 +52,7 @@ function testBytesSyncSAB() {
const sab = new SharedArrayBuffer(5);
new Uint8Array(sab).set([104, 101, 108, 108, 111]); // 'hello'
const data = bytesSync(fromSync(sab));
assert.ok(data.buffer instanceof ArrayBuffer);
assert.deepStrictEqual(data, new Uint8Array([104, 101, 108, 108, 111]));
}
@@ -59,6 +60,7 @@ async function testBytesAsyncSAB() {
const sab = new SharedArrayBuffer(5);
new Uint8Array(sab).set([104, 101, 108, 108, 111]); // 'hello'
const data = await bytes(from(sab));
assert.ok(data.buffer instanceof ArrayBuffer);
assert.deepStrictEqual(data, new Uint8Array([104, 101, 108, 108, 111]));
}
@@ -80,7 +82,7 @@ function testArrayBufferSyncSAB() {
const sab = new SharedArrayBuffer(4);
new Uint8Array(sab).set([1, 2, 3, 4]);
const result = arrayBufferSync(fromSync(sab));
assert.ok(result instanceof SharedArrayBuffer || result instanceof ArrayBuffer);
assert.ok(result instanceof ArrayBuffer);
assert.deepStrictEqual(new Uint8Array(result), new Uint8Array([1, 2, 3, 4]));
}
@@ -88,7 +90,7 @@ async function testArrayBufferAsyncSAB() {
const sab = new SharedArrayBuffer(4);
new Uint8Array(sab).set([1, 2, 3, 4]);
const result = await arrayBuffer(from(sab));
assert.ok(result instanceof SharedArrayBuffer || result instanceof ArrayBuffer);
assert.ok(result instanceof ArrayBuffer);
assert.deepStrictEqual(new Uint8Array(result), new Uint8Array([1, 2, 3, 4]));
}