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

將 ReadableStream 轉換為字串

Bun 提供了多種便利方法,用於將 ReadableStream 的內容讀取為其他格式。要將流讀取為字串,請呼叫其 text() 方法。

TypeScript
const stream = new ReadableStream();
const str = await stream.text();

Bun.readableStreamToText(stream) 具有相同的功能,但已棄用,推薦使用 stream.text()。


請參閱 Bun 的其他 ReadableStream 轉換函式。