Files
bun.sh/docs/guides/streams/node-readable-to-uint8array.md
Meghan Denny 5caca9cd48 add .bytes() method to various readables (#11104)
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Co-authored-by: nektro <nektro@users.noreply.github.com>
2024-05-16 19:10:50 -07:00

12 lines
400 B
Markdown

---
name: Convert a Node.js Readable to an Uint8Array
---
To convert a Node.js `Readable` stream to an `Uint8Array` in Bun, you can create a new `Response` object with the stream as the body, then use `bytes()` to read the stream into an `Uint8Array`.
```ts
import { Readable } from "stream";
const stream = Readable.from(["Hello, ", "world!"]);
const buf = await new Response(stream).bytes();
```