Missing close call on blob-get-stream causes the stream to never finish reading

Open
#206 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript
Domain
api

Research direction

Start with the File API blob-get-stream algorithm and the Streams specification's ReadableStream close algorithm. Reproduce the supplied Blob.stream() BYOB-reader example and verify that reading eventually returns done=true after all bytes are queued.

Written by the indexing model from the issue text.

Description

I believe blog get stream algorithm is missing a call to close that stream, which results in consumers of that readable stream never 'finishing' reading that stream.

For example, without a call to "close", from my reading 'done' will never get set to true for the following test:

let buffer = new ArrayBuffer(200);
let bytesReceived = 0;
let offset = 0;

let blob = new Blob(['Data to be read! 🦬']);

const stream = blob.stream();
const reader = stream.getReader({ mode: "byob" });

while (true) {
  let result = await reader.read(new type(buffer, offset, buffer.byteLength - offset));

  if (result.done) {
    return;
  }

  buffer = result.value.buffer;
  offset += result.value.byteLength;
  bytesReceived += result.value.byteLength;
}

I think the fix should be just adding a close into the blob-get-stream algorithm after all bytes have been queued into the stream.

Dominant language
HTML
Stars
118
Forks
52
Avg merge
9d 16h
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from w3c/FileAPI

All issues in w3c/FileAPI

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.