Skip to content

Commit 1085f4f

Browse files
authored
Add bytes() method to Body mixin
Returns a Uint8Array as opposed to requiring users to get an ArrayBuffer and wrap it. Tests: web-platform-tests/wpt#46198. Fixes #1732.
1 parent 5d9d67b commit 1085f4f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

fetch.bs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7162,6 +7162,7 @@ interface mixin Body {
71627162
readonly attribute boolean bodyUsed;
71637163
[NewObject] Promise<ArrayBuffer> arrayBuffer();
71647164
[NewObject] Promise<Blob> blob();
7165+
[NewObject] Promise<Uint8Array> bytes();
71657166
[NewObject] Promise<FormData> formData();
71667167
[NewObject] Promise<any> json();
71677168
[NewObject] Promise<USVString> text();
@@ -7195,6 +7196,9 @@ due course.
71957196
<dt><code><var>requestOrResponse</var> . <a method for=Body>blob</a>()</code>
71967197
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{Blob}}.
71977198

7199+
<dt><code><var>requestOrResponse</var> . <a method for=Body>bytes</a>()</code>
7200+
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{Uint8Array}}.
7201+
71987202
<dt><code><var>requestOrResponse</var> . <a method for=Body>formData</a>()</code>
71997203
<dd><p>Returns a promise fulfilled with <var>requestOrResponse</var>'s body as {{FormData}}.
72007204

@@ -7290,6 +7294,15 @@ and whose {{Blob/type}} attribute is the result of <a for=Body>get the MIME type
72907294
<!-- This is wrong. It should really set an underlying concept to this. -->
72917295
</div>
72927296

7297+
<div algorithm>
7298+
<p>The <dfn method for=Body><code>bytes()</code></dfn> method steps are to return the result
7299+
of running <a for=Body>consume body</a> with <a>this</a> and the following step given a
7300+
<a for=/>byte sequence</a> <var>bytes</var>: return the result of [=ArrayBufferView/create|creating=] a
7301+
{{Uint8Array}} from <var>bytes</var> in <a>this</a>'s <a>relevant realm</a>.
7302+
7303+
<p class="note">The above method can reject with a {{RangeError}}.
7304+
</div>
7305+
72937306
<div algorithm>
72947307
<p>The <dfn method for=Body><code>formData()</code></dfn> method steps are to return the result of
72957308
running <a for=Body>consume body</a> with <a>this</a> and the following steps given a

0 commit comments

Comments
 (0)