fetch
fetch copied to clipboard
add a method to get a Uint8Array to Body
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 https://github.com/whatwg/fetch/issues/1675 while specifying.)