lib: allow respondWithNewView on byob auto allocated streams

Fixes: https://github.com/nodejs/node/issues/41886

PR-URL: https://github.com/nodejs/node/pull/41887
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
Sean Quinlan authored and GitHub committed 2022-02-16 22:28:56 +00:00
1 parent 0a722973cb
commit 26f9a91cc9
2 files changed
+31

No files matched your search

@@ -2604,6 +2604,7 @@ function readableByteStreamControllerPullSteps(controller, readRequest) {
pendingPullIntos,
{
buffer,
bufferByteLength: autoAllocateChunkSize,
byteOffset: 0,
byteLength: autoAllocateChunkSize,
bytesFilled: 0,
@@ -232,3 +232,33 @@ class Source {
code: 'ERR_INVALID_STATE',
});
}
{
const stream = new ReadableStream({
type: 'bytes',
pull(c) {
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
v.set([20, 21, 22]);
c.byobRequest.respondWithNewView(v);
},
});
const buffer = new ArrayBuffer(10);
const view = new Uint8Array(buffer, 0, 3);
view.set([10, 11, 12]);
const reader = stream.getReader({ mode: 'byob' });
reader.read(view);
}
{
const stream = new ReadableStream({
type: 'bytes',
autoAllocateChunkSize: 10,
pull(c) {
const v = new Uint8Array(c.byobRequest.view.buffer, 0, 3);
v.set([20, 21, 22]);
c.byobRequest.respondWithNewView(v);
},
});
const reader = stream.getReader();
reader.read();
}