add a method to get a Uint8Array to Body
bakkot opened this issue · 4 comments
bakkot commented
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.)
annevk commented
FWIW, WebKit is okay with adding this.
cc @valenting @ricea
valenting commented
Sounds good to me, but I'd like @saschanaz 's opinion as well.
saschanaz commented
Sounds okay to me.
ricea commented
Chromium supports.