Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bytes() method to Blob for reading bytes into a Uint8Array #198

Merged
merged 1 commit into from
May 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ interface Blob {
[NewObject] ReadableStream stream();
[NewObject] Promise<USVString> text();
[NewObject] Promise<ArrayBuffer> arrayBuffer();
[NewObject] Promise<Uint8Array> bytes();
};

enum EndingType { "transparent", "native" };
Expand Down Expand Up @@ -632,6 +633,17 @@ The <dfn method for=Blob>arrayBuffer()</dfn> method, when invoked, must run thes
1. Return the result of transforming |promise| by a fulfillment handler that returns
a new {{ArrayBuffer}} whose contents are its first argument.

### The {{Blob/bytes()}} method ### {#bytes-method-algo}

The <dfn method for=Blob>bytes()</dfn> method, when invoked, must run these steps:

1. Let |stream| be the result of calling [=get stream=] on [=this=].
1. Let |reader| be the result of [=get a reader|getting a reader=] from |stream|.
If that threw an exception, return a new promise rejected with that exception.
1. Let |promise| be the result of [=read all bytes|reading all bytes=] from |stream| with |reader|.
1. Return the result of transforming |promise| by a fulfillment handler that returns
a new {{Uint8Array}} wrapping an {{ArrayBuffer}} containing its first argument.

<!--
████████ ████ ██ ████████
██ ██ ██ ██
Expand Down
Loading