@@ -464,12 +464,12 @@ particularly important for the data structure described in [[#queue-with-sizes]]
464464 offset that bytes were written to as its <code> byteOffset</code> property, and the number of
465465 bytes that were written as its <code> byteLength</code> property.
466466
467- Note that this example is mostly educational. For practical purposes,
468- {{ReadableStreamBYOBReader/fill() }} provides an easier and more direct way to read an exact
469- number of bytes:
467+ Note that this example is mostly educational. For practical purposes, the
468+ {{ReadableStreamBYOBReaderReadOptions/atLeast }} option of {{ReadableStreamBYOBReader/ read()}}
469+ provides an easier and more direct way to read an exact number of bytes:
470470 <xmp highlight="js">
471471 const reader = readableStream.getReader({ mode: "byob" });
472- const { value: view, done } = await reader.fill (new Uint8Array(1024));
472+ const { value: view, done } = await reader.read (new Uint8Array(1024), { atLeast: 1024 } );
473473 console.log("The first 1024 bytes: ", view);
474474 </xmp>
475475</div>
@@ -1312,7 +1312,6 @@ interface ReadableStreamBYOBReader {
13121312 constructor(ReadableStream stream);
13131313
13141314 Promise<ReadableStreamBYOBReadResult> read(ArrayBufferView view, optional ReadableStreamBYOBReaderReadOptions options = {});
1315- Promise<ReadableStreamBYOBReadResult> fill(ArrayBufferView view);
13161315 undefined releaseLock();
13171316};
13181317ReadableStreamBYOBReader includes ReadableStreamGenericReader;
@@ -1384,7 +1383,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
13841383 <p> If the reader is [=active reader|active=] , behaves the same
13851384 <code> |stream|.{{ReadableStream/cancel(reason)|cancel}} (<var ignore> reason</var> )</code> .
13861385
1387- <dt><code> { <var ignore> value</var> , <var ignore> done</var> } = await <var ignore> reader</var> .{{ReadableStreamBYOBReader/read()|read}} (<var ignore> view</var> )</code>
1386+ <dt><code> { <var ignore> value</var> , <var ignore> done</var> } = await <var ignore> reader</var> .{{ReadableStreamBYOBReader/read()|read}} (<var ignore> view</var> [, { {{ReadableStreamBYOBReaderReadOptions/atLeast}} }] )</code>
13881387 <dd>
13891388 <p> Attempts to read bytes into |view|, and returns a promise resolved with the result:
13901389
@@ -1410,34 +1409,13 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
14101409 <p> If reading a chunk causes the queue to become empty, more data will be pulled from the
14111410 [=underlying source=] .
14121411
1413- <dt><code> { <var ignore> value</var> , <var ignore> done</var> } = await <var ignore> reader</var> .{{ReadableStreamBYOBReader/fill()|fill}} (<var ignore> view</var> )</code>
1414- <dd>
1415- <p> Attempts to read bytes into |view| until it is completely full, and returns a promise resolved
1416- with the result:
1417-
1418- <ul>
1419- <li> If enough bytes become available to fill |view|, the promise will be fulfilled with an
1420- object of the form <code highlight="js"> { value: newView, done: false }</code> . In this case,
1421- |view| will be [=ArrayBuffer/detached=] and no longer usable, but <code> newView</code> will be a
1422- new view (of the same type) onto the same backing memory region, with the received bytes written
1423- into it. <code> newView</code> will be completely filled, so its <code> byteLength</code> will
1424- equal |view|'s <code> byteLength</code> .
1425-
1426- <li> If the stream becomes closed before |view| is full, the promise will be fulfilled with an
1427- object of the form <code highlight="js"> { value: newView, done: true }</code> . In this case,
1428- |view| will be [=ArrayBuffer/detached=] and no longer usable, but <code> newView</code> will be a
1429- new view (of the same type) onto the same backing memory region, with any received bytes written
1430- into it. <code> newView.byteLength</code> will equal that number of received bytes.
1431-
1432- <li> If the reader is [=cancel a readable stream|canceled=] , the promise will be fulfilled with
1433- an object of the form <code highlight="js"> { value: undefined, done: true }</code> . In this case,
1434- the backing memory region of |view| is discarded and not returned to the caller.
1435-
1436- <li> If the stream becomes errored, the promise will be rejected with the relevant error.
1437- </ul>
1438-
1439- <p> If filling the view causes the queue to become empty, more data will be pulled from the
1440- [=underlying source=] . This process repeats until either |view| is full, or the stream is closed.
1412+ <p> If {{ReadableStreamBYOBReaderReadOptions/atLeast}} is given, then the promise will only be
1413+ fulfilled as soon as at least the given number of elements are available. Here, the "number of
1414+ elements" is given by <code> newView</code> 's <code> length</code> (for typed arrays) or
1415+ <code> newView</code> 's <code> byteLength</code> (for {{DataView}} s). If the stream becomes closed,
1416+ then the promise is fulfilled with the remaining elements in the stream, which might be fewer than
1417+ the initially requested amount. If not given, then the promise resolves when at least one element
1418+ is available.
14411419
14421420 <dt><code><var ignore> reader</var> .{{ReadableStreamBYOBReader/releaseLock()|releaseLock}} ()</code>
14431421 <dd>
@@ -1501,35 +1479,6 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
15011479 1. Return |promise|.
15021480</div>
15031481
1504- <div algorithm>
1505- The <dfn id="byob-reader-fill" method for="ReadableStreamBYOBReader">fill(|view|)</dfn>
1506- method steps are:
1507-
1508- 1. If |view|.\[[ByteLength]] is 0, return [=a promise rejected with=] a {{TypeError}} exception.
1509- 1. If |view|.\[[ViewedArrayBuffer]] .\[[ArrayBufferByteLength]] is 0, return [=a promise rejected
1510- with=] a {{TypeError}} exception.
1511- 1. If ! [$IsDetachedBuffer$] (|view|.\[[ViewedArrayBuffer]] ) is true, return
1512- [=a promise rejected with=] a {{TypeError}} exception.
1513- 1. If [=this=] .[=ReadableStreamGenericReader/[[stream]]=] is undefined, return [=a promise rejected
1514- with=] a {{TypeError}} exception.
1515- 1. Let |promise| be [=a new promise=] .
1516- 1. Let |readIntoRequest| be a new [=read-into request=] with the following [=struct/items=] :
1517- : [=read-into request/chunk steps=] , given |chunk|
1518- ::
1519- 1. [=Resolve=] |promise| with «[ "{{ReadableStreamBYOBReadResult/value}} " → |chunk|,
1520- "{{ReadableStreamBYOBReadResult/done}} " → false ]».
1521- : [=read-into request/close steps=] , given |chunk|
1522- ::
1523- 1. [=Resolve=] |promise| with «[ "{{ReadableStreamBYOBReadResult/value}} " → |chunk|,
1524- "{{ReadableStreamBYOBReadResult/done}} " → true ]».
1525- : [=read-into request/error steps=] , given |e|
1526- ::
1527- 1. [=Reject=] |promise| with |e|.
1528- 1. Perform ! [$ReadableStreamBYOBReaderRead$] ([=this=] , |view|, |readIntoRequest|,
1529- |view|.\[[ByteLength]] ).
1530- 1. Return |promise|.
1531- </div>
1532-
15331482<div algorithm>
15341483 The <dfn id="byob-reader-release-lock" method
15351484 for="ReadableStreamBYOBReader"> releaseLock()</dfn> method steps are:
@@ -3432,7 +3381,7 @@ The following abstract operations support the implementation of the
34323381 1. Set |totalBytesToCopyRemaining| to |maxAlignedBytes| − |pullIntoDescriptor|'s [=pull-into
34333382 descriptor/bytes filled=] .
34343383 1. Set |ready| to true.
3435- <p class="note"> A descriptor for a {{ReadableStreamBYOBReader/fill ()}} request
3384+ <p class="note"> A descriptor for a {{ReadableStreamBYOBReader/read ()}} request
34363385 that is not yet completely filled will stay at the head of the queue, so the [=underlying source=]
34373386 can keep filling it.
34383387 1. Let |queue| be |controller|.[=ReadableByteStreamController/[[queue]]=] .
@@ -3690,7 +3639,7 @@ The following abstract operations support the implementation of the
36903639 1. Return.
36913640 1. If |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=] < |pullIntoDescriptor|' s
36923641 [=pull-into descriptor/minimum fill=] , return.
3693- <p class="note"> A descriptor for a {{ReadableStreamBYOBReader/fill ()}} request
3642+ <p class="note"> A descriptor for a {{ReadableStreamBYOBReader/read ()}} request
36943643 that is not yet completely filled will stay at the head of the queue, so the [=underlying source=]
36953644 can keep filling it.
36963645 1. Perform ! [$ReadableByteStreamControllerShiftPendingPullInto$] (|controller|).
0 commit comments