From 1085f4fbfeebda8d4fa5efcb6c5c7350953e524b Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Tue, 14 May 2024 00:53:27 -0700 Subject: [PATCH] Add bytes() method to Body mixin Returns a Uint8Array as opposed to requiring users to get an ArrayBuffer and wrap it. Tests: https://github.com/web-platform-tests/wpt/pull/46198. Fixes #1732. --- fetch.bs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fetch.bs b/fetch.bs index 9ef6385f..625f5bd7 100644 --- a/fetch.bs +++ b/fetch.bs @@ -7162,6 +7162,7 @@ interface mixin Body { readonly attribute boolean bodyUsed; [NewObject] Promise<ArrayBuffer> arrayBuffer(); [NewObject] Promise<Blob> blob(); + [NewObject] Promise<Uint8Array> bytes(); [NewObject] Promise<FormData> formData(); [NewObject] Promise<any> json(); [NewObject] Promise<USVString> text(); @@ -7195,6 +7196,9 @@ due course.
requestOrResponse . blob()

Returns a promise fulfilled with requestOrResponse's body as {{Blob}}. +

requestOrResponse . bytes() +

Returns a promise fulfilled with requestOrResponse's body as {{Uint8Array}}. +

requestOrResponse . formData()

Returns a promise fulfilled with requestOrResponse's body as {{FormData}}. @@ -7290,6 +7294,15 @@ and whose {{Blob/type}} attribute is the result of get the MIME type +

+

The bytes() method steps are to return the result +of running consume body with this and the following step given a +byte sequence bytes: return the result of [=ArrayBufferView/create|creating=] a +{{Uint8Array}} from bytes in this's relevant realm. + +

The above method can reject with a {{RangeError}}. +

+

The formData() method steps are to return the result of running consume body with this and the following steps given a