Skip to content

Commit

Permalink
Rename readFully() to fill()
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Oct 13, 2021
1 parent b3df7c2 commit 36c98f7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 37 deletions.
40 changes: 20 additions & 20 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -462,11 +462,11 @@ particularly important for the data structure described in [[#queue-with-sizes]]
bytes that were written as its <code>byteLength</code> property.

Note that this example is mostly educational. For practical purposes,
{{ReadableStreamBYOBReader/readFully()}} provides an easier and more direct way to read an exact
{{ReadableStreamBYOBReader/fill()}} provides an easier and more direct way to read an exact
number of bytes:
<xmp highlight="js">
const reader = readableStream.getReader({ mode: "byob" });
const { value: view, done } = await reader.readFully(new Uint8Array(1024));
const { value: view, done } = await reader.fill(new Uint8Array(1024));
console.log("The first 1024 bytes: ", view);
</xmp>
</div>
Expand Down Expand Up @@ -1298,7 +1298,7 @@ interface ReadableStreamBYOBReader {
constructor(ReadableStream stream);

Promise<ReadableStreamBYOBReadResult> read(ArrayBufferView view);
Promise<ReadableStreamBYOBReadResult> readFully(ArrayBufferView view);
Promise<ReadableStreamBYOBReadResult> fill(ArrayBufferView view);
undefined releaseLock();
};
ReadableStreamBYOBReader includes ReadableStreamGenericReader;
Expand Down Expand Up @@ -1392,7 +1392,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
<p>If reading a chunk causes the queue to become empty, more data will be pulled from the
[=underlying source=].

<dt><code>{ <var ignore>value</var>, <var ignore>done</var> } = await <var ignore>reader</var>.{{ReadableStreamBYOBReader/readFully()|readFully}}(<var ignore>view</var>)</code>
<dt><code>{ <var ignore>value</var>, <var ignore>done</var> } = await <var ignore>reader</var>.{{ReadableStreamBYOBReader/fill()|fill}}(<var ignore>view</var>)</code>
<dd>
<p>Attempts to read bytes into |view| until it is completely full, and returns a promise resolved
with the result:
Expand Down Expand Up @@ -1470,7 +1470,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
</div>

<div algorithm>
The <dfn id="byob-reader-read-fully" method for="ReadableStreamBYOBReader">readFully(|view|)</dfn>
The <dfn id="byob-reader-fill" method for="ReadableStreamBYOBReader">fill(|view|)</dfn>
method steps are:

1. If |view|.\[[ByteLength]] is 0, return [=a promise rejected with=] a {{TypeError}} exception.
Expand All @@ -1493,7 +1493,7 @@ value: newViewOnSameMemory, done: true }</code> for closed streams. If the strea
: [=read-into request/error steps=], given |e|
::
1. [=Reject=] |promise| with |e|.
1. Perform ! [$ReadableStreamBYOBReaderReadFully$]([=this=], |view|, |readIntoRequest|).
1. Perform ! [$ReadableStreamBYOBReaderFill$]([=this=], |view|, |readIntoRequest|).
1. Return |promise|.
</div>

Expand Down Expand Up @@ -1823,8 +1823,8 @@ has the following [=struct/items=]:
: <dfn for="pull-into descriptor">reader type</dfn>
:: Either "`default`" or "`byob`", indicating what type of [=readable stream reader=] initiated this
request
: <dfn for="pull-into descriptor">read fully</dfn>
:: A boolean flag indicating whether this is a {{ReadableStreamBYOBReader/readFully()}} request.
: <dfn for="pull-into descriptor">fill</dfn>
:: A boolean flag indicating whether this is a {{ReadableStreamBYOBReader/fill()}} request.

<h4 id="rbs-controller-prototype">Methods and properties</h4>

Expand Down Expand Up @@ -1954,7 +1954,7 @@ counterparts for default controllers, as discussed in [[#rs-abstract-ops-used-by
[=pull-into descriptor/byte offset=] 0, [=pull-into descriptor/byte length=]
|autoAllocateChunkSize|, [=pull-into descriptor/bytes filled=] 0, [=pull-into
descriptor/element size=] 1, [=pull-into descriptor/view constructor=] {{%Uint8Array%}},
[=pull-into descriptor/reader type=] "`default`", and [=pull-into descriptor/read fully=]
[=pull-into descriptor/reader type=] "`default`", and [=pull-into descriptor/fill=]
false.
1. [=list/Append=] |pullIntoDescriptor| to
[=this=].[=ReadableByteStreamController/[[pendingPullIntos]]=].
Expand Down Expand Up @@ -2845,8 +2845,8 @@ The following abstract operations support the implementation and manipulation of
</div>

<div algorithm>
<dfn abstract-op lt="ReadableStreamBYOBReaderReadFully"
id="readable-stream-byob-reader-read-fully">ReadableStreamBYOBReaderReadFully(|reader|, |view|,
<dfn abstract-op lt="ReadableStreamBYOBReaderFill"
id="readable-stream-byob-reader-fill">ReadableStreamBYOBReaderFill(|reader|, |view|,
|readIntoRequest|)</dfn> performs the following steps:

1. Let |stream| be |reader|.[=ReadableStreamGenericReader/[[stream]]=].
Expand Down Expand Up @@ -3191,7 +3191,7 @@ The following abstract operations support the implementation of the
1. Assert: |stream|.[=ReadableStream/[[state]]=] is not "`errored`".
1. Let |done| be false.
1. If |stream|.[=ReadableStream/[[state]]=] is "`closed`",
1. If |pullIntoDescriptor|'s [=pull-into descriptor/read fully=] is true,
1. If |pullIntoDescriptor|'s [=pull-into descriptor/fill=] is true,
1. Assert: |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=]
mod |pullIntoDescriptor|'s [=pull-into descriptor/element size=] is 0.
1. Otherwise,
Expand Down Expand Up @@ -3321,14 +3321,14 @@ The following abstract operations support the implementation of the
|maxBytesToCopy|.
1. Let |totalBytesToCopyRemaining| be |maxBytesToCopy|.
1. Let |ready| be false.
1. If |pullIntoDescriptor|'s [=pull-into descriptor/read fully=] is true,
1. If |pullIntoDescriptor|'s [=pull-into descriptor/fill=] is true,
1. Assert: |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=] < |pullIntoDescriptor|'s
[=pull-into descriptor/byte length=].
1. If |maxBytesFilled| ≥ |pullIntoDescriptor|'s [=pull-into descriptor/byte length=],
1. Set |totalBytesToCopyRemaining| to |pullIntoDescriptor|'s [=pull-into descriptor/byte length=]
− |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=].
1. Set |ready| to true.
<p class="note">A descriptor for a {{ReadableStreamBYOBReader/readFully()}} request
<p class="note">A descriptor for a {{ReadableStreamBYOBReader/fill()}} request
that is not yet completely filled will stay at the head of the queue, so the [=underlying source=]
can keep filling it.
1. Otherwise,
Expand Down Expand Up @@ -3366,7 +3366,7 @@ The following abstract operations support the implementation of the
1. If |ready| is false,
1. Assert: |controller|.[=ReadableByteStreamController/[[queueTotalSize]]=] is 0.
1. Assert: |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=] > 0.
1. If |pullIntoDescriptor|'s [=pull-into descriptor/read fully=] is true,
1. If |pullIntoDescriptor|'s [=pull-into descriptor/fill=] is true,
1. Assert: |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=] &lt;
|pullIntoDescriptor|'s [=pull-into descriptor/byte length=].
1. Otherwise,
Expand Down Expand Up @@ -3458,7 +3458,7 @@ The following abstract operations support the implementation of the
<div algorithm>
<dfn abstract-op lt="ReadableByteStreamControllerPullInto"
id="readable-byte-stream-controller-pull-into">ReadableByteStreamControllerPullInto(|controller|,
|view|, |readIntoRequest|, |readFully|)</dfn> performs the following steps:
|view|, |readIntoRequest|, |fill|)</dfn> performs the following steps:

1. Let |stream| be |controller|.[=ReadableByteStreamController/[[stream]]=].
1. Let |elementSize| be 1.
Expand All @@ -3480,7 +3480,7 @@ The following abstract operations support the implementation of the
[=pull-into descriptor/byte offset=] |byteOffset|, [=pull-into descriptor/byte length=]
|byteLength|, [=pull-into descriptor/bytes filled=] 0, [=pull-into descriptor/element size=]
|elementSize|, [=pull-into descriptor/view constructor=] |ctor|, [=pull-into
descriptor/reader type=] "`byob`", and [=pull-into descriptor/read fully=] |readFully|.
descriptor/reader type=] "`byob`", and [=pull-into descriptor/fill=] |fill|.
1. If |controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=] is not empty,
1. [=list/Append=] |pullIntoDescriptor| to
|controller|.[=ReadableByteStreamController/[[pendingPullIntos]]=].
Expand Down Expand Up @@ -3536,7 +3536,7 @@ The following abstract operations support the implementation of the
id="readable-byte-stream-controller-respond-in-closed-state">ReadableByteStreamControllerRespondInClosedState(|controller|,
|firstDescriptor|)</dfn> performs the following steps:

1. If |firstDescriptor|'s [=pull-into descriptor/read fully=] is true,
1. If |firstDescriptor|'s [=pull-into descriptor/fill=] is true,
1. Assert: |firstDescriptor|'s [=pull-into descriptor/bytes filled=] mod |firstDescriptor|'s
[=pull-into descriptor/element size=] is 0.
1. Otherwise,
Expand All @@ -3561,10 +3561,10 @@ The following abstract operations support the implementation of the
|bytesWritten|, |pullIntoDescriptor|).
1. If |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=] &lt; |pullIntoDescriptor|'s
[=pull-into descriptor/element size=], return.
1. If |pullIntoDescriptor|'s [=pull-into descriptor/read fully=] is true and |pullIntoDescriptor|'s
1. If |pullIntoDescriptor|'s [=pull-into descriptor/fill=] is true and |pullIntoDescriptor|'s
[=pull-into descriptor/bytes filled=] &lt; |pullIntoDescriptor|'s
[=pull-into descriptor/byte length=], return.
<p class="note">A descriptor for a {{ReadableStreamBYOBReader/readFully()}} request
<p class="note">A descriptor for a {{ReadableStreamBYOBReader/fill()}} request
that is not yet completely filled will stay at the head of the queue, so the [=underlying source=]
can keep filling it.
1. Perform ! [$ReadableByteStreamControllerShiftPendingPullInto$](|controller|).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ exports.implementation = class ReadableByteStreamControllerImpl {
elementSize: 1,
viewConstructor: Uint8Array,
readerType: 'default',
readFully: false
fill: false
};

this._pendingPullIntos.push(pullIntoDescriptor);
Expand Down
6 changes: 3 additions & 3 deletions reference-implementation/lib/ReadableStreamBYOBReader-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ReadableStreamBYOBReaderImpl {
return promise;
}

readFully(view) {
fill(view) {
if (view.byteLength === 0) {
return promiseRejectedWith(new TypeError('view must have non-zero byteLength'));
}
Expand All @@ -48,7 +48,7 @@ class ReadableStreamBYOBReaderImpl {
}

if (this._stream === undefined) {
return promiseRejectedWith(readerLockException('readFully'));
return promiseRejectedWith(readerLockException('fill'));
}

const promise = newPromise();
Expand All @@ -57,7 +57,7 @@ class ReadableStreamBYOBReaderImpl {
closeSteps: chunk => resolvePromise(promise, { value: chunk, done: true }),
errorSteps: e => rejectPromise(promise, e)
};
aos.ReadableStreamBYOBReaderReadFully(this, view, readIntoRequest);
aos.ReadableStreamBYOBReaderFill(this, view, readIntoRequest);
return promise;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ interface ReadableStreamBYOBReader {
constructor(ReadableStream stream);

Promise<ReadableStreamBYOBReadResult> read(ArrayBufferView view);
Promise<ReadableStreamBYOBReadResult> readFully(ArrayBufferView view);
Promise<ReadableStreamBYOBReadResult> fill(ArrayBufferView view);
void releaseLock();
};
ReadableStreamBYOBReader includes ReadableStreamGenericReader;
22 changes: 11 additions & 11 deletions reference-implementation/lib/abstract-ops/readable-streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ Object.assign(exports, {
ReadableByteStreamControllerRespond,
ReadableByteStreamControllerRespondWithNewView,
ReadableStreamAddReadRequest,
ReadableStreamBYOBReaderFill,
ReadableStreamBYOBReaderRead,
ReadableStreamBYOBReaderReadFully,
ReadableStreamCancel,
ReadableStreamClose,
ReadableStreamDefaultControllerCallPullIfNeeded,
Expand Down Expand Up @@ -929,7 +929,7 @@ function ReadableStreamBYOBReaderRead(reader, view, readIntoRequest) {
}
}

function ReadableStreamBYOBReaderReadFully(reader, view, readIntoRequest) {
function ReadableStreamBYOBReaderFill(reader, view, readIntoRequest) {
const stream = reader._stream;

assert(stream !== undefined);
Expand Down Expand Up @@ -1277,7 +1277,7 @@ function ReadableByteStreamControllerCommitPullIntoDescriptor(stream, pullIntoDe

let done = false;
if (stream._state === 'closed') {
if (pullIntoDescriptor.readFully) {
if (pullIntoDescriptor.fill) {
assert(pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize === 0);
} else {
assert(pullIntoDescriptor.bytesFilled === 0);
Expand Down Expand Up @@ -1389,9 +1389,9 @@ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller,

let totalBytesToCopyRemaining = maxBytesToCopy;
let ready = false;
if (pullIntoDescriptor.readFully) {
if (pullIntoDescriptor.fill) {
assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.byteLength);
// A descriptor for a readFully() request that is not yet completely filled will stay at the head of the queue,
// A descriptor for a fill() request that is not yet completely filled will stay at the head of the queue,
// so the underlying source can keep filling it.
if (maxBytesFilled >= pullIntoDescriptor.byteLength) {
totalBytesToCopyRemaining = pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled;
Expand Down Expand Up @@ -1432,7 +1432,7 @@ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller,
if (ready === false) {
assert(controller._queueTotalSize === 0);
assert(pullIntoDescriptor.bytesFilled > 0);
if (pullIntoDescriptor.readFully) {
if (pullIntoDescriptor.fill) {
assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.byteLength);
} else {
assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);
Expand Down Expand Up @@ -1513,7 +1513,7 @@ function ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(contro
}
}

function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest, readFully) {
function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest, fill) {
const stream = controller._stream;

let elementSize = 1;
Expand All @@ -1540,7 +1540,7 @@ function ReadableByteStreamControllerPullInto(controller, view, readIntoRequest,
elementSize,
viewConstructor: ctor,
readerType: 'byob',
readFully
fill
};

if (controller._pendingPullIntos.length > 0) {
Expand Down Expand Up @@ -1611,7 +1611,7 @@ function ReadableByteStreamControllerRespond(controller, bytesWritten) {
}

function ReadableByteStreamControllerRespondInClosedState(controller, firstDescriptor) {
if (firstDescriptor.readFully) {
if (firstDescriptor.fill) {
assert(firstDescriptor.bytesFilled % firstDescriptor.elementSize === 0);
} else {
assert(firstDescriptor.bytesFilled === 0);
Expand All @@ -1635,8 +1635,8 @@ function ReadableByteStreamControllerRespondInReadableState(controller, bytesWri
return;
}

if (pullIntoDescriptor.readFully && pullIntoDescriptor.bytesFilled < pullIntoDescriptor.byteLength) {
// A descriptor for a readFully() request that is not yet completely filled will stay at the head of the queue,
if (pullIntoDescriptor.fill && pullIntoDescriptor.bytesFilled < pullIntoDescriptor.byteLength) {
// A descriptor for a fill() request that is not yet completely filled will stay at the head of the queue,
// so the underlying source can keep filling it.
return;
}
Expand Down
2 changes: 1 addition & 1 deletion reference-implementation/web-platform-tests

0 comments on commit 36c98f7

Please sign in to comment.