From a469c79c0be30047e73cf23411633c711b5e932b Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Fri, 10 May 2024 09:07:59 -0700 Subject: [PATCH 1/2] Add bytes() method to Blob for reading bytes into a Uint8Array --- index.bs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/index.bs b/index.bs index 3ae9404..6dab918 100644 --- a/index.bs +++ b/index.bs @@ -300,6 +300,7 @@ interface Blob { [NewObject] ReadableStream stream(); [NewObject] Promise text(); [NewObject] Promise arrayBuffer(); + [NewObject] Promise bytes(); }; enum EndingType { "transparent", "native" }; @@ -632,6 +633,17 @@ The arrayBuffer() 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 bytes() 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. +