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 a method to get a Uint8Array to Body #1732

Closed
bakkot opened this issue Jan 29, 2024 · 4 comments · Fixed by #1753
Closed

add a method to get a Uint8Array to Body #1732

bakkot opened this issue Jan 29, 2024 · 4 comments · Fixed by #1753
Labels
addition/proposal New features or enhancements topic: api

Comments

@bakkot
Copy link
Contributor

bakkot commented Jan 29, 2024

What problem are you trying to solve?

Body has an .arrayBuffer() method, but that's almost never what you actually want, since you can't read out of a buffer directly - you need a view. Uint8Array is the canonical "sequence of byte values" view.

What solutions exist today?

new Uint8Array(await body.arrayBuffer())

How would you solve it?

Add a .bytes() method which gives a new Uint8Array.

Anything else?

Some brief discussion here.

PushMessageData and Blob (which live elsewhere) would need this too, since they just copied Body.

(Also, watch out for #1675 while specifying.)

@bakkot bakkot added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Jan 29, 2024
@annevk
Copy link
Member

annevk commented Apr 4, 2024

FWIW, WebKit is okay with adding this.

cc @valenting @ricea

@valenting
Copy link

Sounds good to me, but I'd like @saschanaz 's opinion as well.

@saschanaz
Copy link
Member

Sounds okay to me.

@annevk annevk added needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan and removed needs implementer interest Moving the issue forward requires implementers to express interest labels Apr 4, 2024
@ricea
Copy link
Collaborator

ricea commented Apr 19, 2024

Chromium supports.

annevk pushed a commit that referenced this issue May 14, 2024
Returns a Uint8Array as opposed to requiring users to get an ArrayBuffer and wrap it.

Tests: web-platform-tests/wpt#46198.

Fixes #1732.
@annevk annevk removed the needs concrete proposal Moving the issue forward requires someone to figure out a detailed plan label May 26, 2024
aarongable pushed a commit to chromium/chromium that referenced this issue Oct 3, 2024
This CL adds a bytes() method to get Uint8Array to body, instead of
requiring users to get an ArrayBuffer with arrayBuffer() and wrap it.

whatwg/fetch#1732
https://chromestatus.com/feature/5239268180754432

Bug: 340206277
Change-Id: I48a96970450592bcbae7d0a8b79f68b9bd0b556b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5895865
Reviewed-by: Rick Byers <rbyers@chromium.org>
Reviewed-by: Adam Rice <ricea@chromium.org>
Commit-Queue: Perry <perryuwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1363676}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements topic: api
Development

Successfully merging a pull request may close this issue.

5 participants