Bun

指南串流

使用 Bun 將 Node.js Readable 轉換為 Uint8Array

若要在 Bun 中將 Node.js Readable 串流轉換為 Uint8Array,您可以建立一個新的 Response 物件,並將該串流作為主體,然後使用 bytes() 將串流讀取到 Uint8Array 中。

import { Readable } from "stream";
const stream = Readable.from(["Hello, ", "world!"]);
const buf = await new Response(stream).bytes();