Re: [whatwg/streams] Add ReadableStreamBYOBReader.readFully() (#1145)

@domenic approved this pull request.

Sorry for the delay. This LGTM with the minor potential improvement of combining the boolean with reader type. @ricea do you think we could implement this? Shouldn't take long...

> @@ -1382,6 +1392,34 @@ 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>
+ <dd>
+  <p>Attempts to read bytes into |view| until it is completely full, and returns a promise resolved
+  with the result:
+
+  <ul>
+   <li>If enough bytes become available to fill |view|, the promise will be fulfilled with an
+   object  of the form <code highlight="js">{ value: theView, done: false }</code>. In this case,
+   |view| will be [=ArrayBuffer/detached=] and no longer usable, but <code>theView</code> will be a

"view" vs. "theView" is confusing. Above we use "view" vs. "theChunk" which is OK. We could also change both to "view" vs. "newView".

> + <dd>
+  <p>Attempts to read bytes into |view| until it is completely full, and returns a promise resolved
+  with the result:
+
+  <ul>
+   <li>If enough bytes become available to fill |view|, the promise will be fulfilled with an
+   object  of the form <code highlight="js">{ value: theView, done: false }</code>. In this case,
+   |view| will be [=ArrayBuffer/detached=] and no longer usable, but <code>theView</code> will be a
+   new view (of the same type) onto the same backing memory region, with the received bytes written
+   into it.
+
+   <li>If the stream becomes closed before |view| is full, the promise will be fulfilled with an
+   object of the form <code highlight="js">{ value: theView, done: true }</code>. In this case,
+   |view| will be [=ArrayBuffer/detached=] and no longer usable, but <code>theChunk</code> will be a
+   new view (of the same type) onto the same backing memory region, with any received bytes written
+   into it.

Maybe mention that its `byteLength` will be equal to the number of bytes read?

> +: <dfn for="pull-into descriptor">read fully</dfn>
+:: A boolean flag indicating whether this is a {{ReadableStreamBYOBReader/readFully()}} request.

Boolean seems fine to me. If we can combine them (i.e., if one element in the 2x2 matrix is not currently filled out) that sounds even nicer.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/1145#pullrequestreview-729961336

Received on Friday, 13 August 2021 20:54:32 UTC