Skip to content

Bun 提供了許多便捷函數,用於將 ReadableStream 的內容讀取為不同格式。此代碼片段將 ReadableStream 的內容讀取為 ArrayBuffer,然後創建一個指向它的 Buffer

ts
const stream = new ReadableStream();
const arrBuf = await Bun.readableStreamToArrayBuffer(stream);
const nodeBuf = Buffer.from(arrBuf);

請參閱 文檔 > API > 工具函數 獲取 Bun 其他 ReadableStream 轉換函數的文檔。

Bun學習網由www.bunjs.com.cn整理維護