fetch icon indicating copy to clipboard operation
fetch copied to clipboard

add a method to get a Uint8Array to Body

Open bakkot opened this issue 1 year ago • 0 comments

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.)

bakkot avatar Jan 29 '24 23:01 bakkot