w3c / w3c/FileAPI

Support using AbortController with FileAPI

Open
#159 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Hey,

It would be useful to use the web platform standard cancellation method to abort readers.
Other web platform code (like fetch) supports cancellation through signals.

Code before:

async function readFile(file, { signal }) {
  var reader = new FileReader();
  const handler = e => reader.abort();
  signal.addEventListener('abort', handler, { once: true });
  reader.addEventListener('load', () => signal.removeEventListener('abort', handler));
  reader.addEventListener('error', () => signal.removeEventListener('abort', handler));
  const p = new Promise((resolve, reject) => {
    reader.onload = (e) => resolve(e.target.result);
    reader.onerror = (e) => reject(reader.error);
  });
  reader.readAsText(file);
  return await p;
}

Possible suggested change, assuming signal support:

async function readFile(file, { signal }) {
  var reader = new FileReader({ signal });
  const p = new Promise((resolve, reject) => {
    reader.onload = (e) => resolve(e.target.result);
    reader.onerror = (e) => reject(reader.error);
  });
  reader.readAsText(file);
  return await p;
}

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.

Research direction

Start with the FileReader and AbortController examples in the issue, then read the FileAPI specification entry points for FileReader construction, reading, aborting, and error handling. Define the signal-support behavior and its interaction with existing reader events; done means the specification consistently describes cancellation and its observable results.

Written by the indexing model from the issue text.

Assessment

Tech stack
html, javascript
Domain
api
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.