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

@MattiasBuelens commented on this pull request.



> +  if (pullIntoDescriptor.readFully) {
+    // A descriptor for a readFully() 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;
+      ready = true;
+    }

At the end of this function, we assert that if `ready === false`, then `controller._queueTotalSize === 0`. In other words, if the pull-into descriptor is not ready yet, then we must have drained the entire queue into the descriptor. With [the previous implementation](https://github.com/whatwg/streams/blob/383c9e543a63938a2c2497a627b0a216d89e7250/reference-implementation/lib/abstract-ops/readable-streams.js#L1366-L1371), we would incorrectly leave some unaligned bytes in the queue if they would not fill up the entire descriptor. With the new implementation, we always copy those bytes.

I added [a new test](https://github.com/web-platform-tests/wpt/blob/984cdd21400ba73419bad9fe66884c5d2436bbf6/streams/readable-byte-streams/read-fully.any.js#L476-L491) for this specific edge case.

-- 
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-713303390

Received on Thursday, 22 July 2021 23:13:56 UTC