Skip to content

Commit 85b18bc

Browse files
Add bytes() method for reading bytes into a Uint8Array (#198)
1 parent 5f1f9f5 commit 85b18bc

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

index.bs

+12
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ interface Blob {
300300
[NewObject] ReadableStream stream();
301301
[NewObject] Promise<USVString> text();
302302
[NewObject] Promise<ArrayBuffer> arrayBuffer();
303+
[NewObject] Promise<Uint8Array> bytes();
303304
};
304305

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

636+
### The {{Blob/bytes()}} method ### {#bytes-method-algo}
637+
638+
The <dfn method for=Blob>bytes()</dfn> method, when invoked, must run these steps:
639+
640+
1. Let |stream| be the result of calling [=get stream=] on [=this=].
641+
1. Let |reader| be the result of [=get a reader|getting a reader=] from |stream|.
642+
If that threw an exception, return a new promise rejected with that exception.
643+
1. Let |promise| be the result of [=read all bytes|reading all bytes=] from |stream| with |reader|.
644+
1. Return the result of transforming |promise| by a fulfillment handler that returns
645+
a new {{Uint8Array}} wrapping an {{ArrayBuffer}} containing its first argument.
646+
635647
<!--
636648
████████ ████ ██ ████████
637649
██ ██ ██ ██

0 commit comments

Comments
 (0)