執行環境套件管理器打包器測試執行器程式碼檢查格式化指南參考部落格意見回饋

將 Node.js Readable 轉換為 Uint8Array

要在 Bun 中將 Node.js Readable 流轉換為 Uint8Array,請以該流作為正文建立一個 Response,然後呼叫 bytes()。

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