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

@MattiasBuelens commented on this pull request.



>  
   let totalBytesToCopyRemaining = maxBytesToCopy;
   let ready = false;
-  if (maxAlignedBytes > currentAlignedBytes) {
-    totalBytesToCopyRemaining = maxAlignedBytes - pullIntoDescriptor.bytesFilled;
-    ready = true;
+  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;
+    }
+  } else {
+    const maxAlignedBytes = maxBytesFilled - maxBytesFilled % elementSize;
+    if (maxAlignedBytes > currentAlignedBytes) {

I'm pretty sure this is right, so I changed it. I added some asserts for good measure. 😁

-- 
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#discussion_r675911145

Received on Friday, 23 July 2021 23:37:28 UTC