v132 · network / connectivity
Fetch: Request.bytes() and Response.bytes()
Add a bytes() method to the Request and Response interfaces, which returns a promise that resolves with a Uint8Array. While Request and Response have an arrayBuffer() method, we can't read directly from a buffer. We have to create a view such as a Uint8Array to read it. The bytes() method improves the ergonomics of getting the body of Request and Response.
concepts
-
Request/Response.bytes()
Request.bytes() and Response.bytes() — direct Uint8Array reads. Saves the double-allocation of arrayBuffer() → typed array.
-
request.bytes() upload side
The upload side: construct a Request with a text or file body, read it back as Uint8Array, surface length and hex.
-
side-by-side bytes()
Fetch the same URL through
arrayBuffer()+ Uint8Array wrap and throughbytes(). Compare byteLength, hex dump, and elapsed time. -
Body API comparator
Six Body methods, four recipes (upload, image header, stream, service worker rewrite). Cheat sheet for when to pick which.
why it shipped
Add a bytes() method to the Request and Response interfaces, It improves the ergonomics of getting the body of Request and Response.