Bun

指南

使用 Bun 將 Node.js Readable 轉換為字串

要在 Bun 中將 Node.js Readable 流轉換為字串,您可以建立一個新的 Response 物件,並將流作為其 body,然後使用 response.text() 將流讀取為字串。

import { Readable } from "stream";
const stream = Readable.from([Buffer.from("Hello, world!")]);
const text = await new Response(stream).text();
console.log(text); // "Hello, world!"