若要將 Node.js Readable
串流轉換為 Bun 中的 JSON 物件,你可以建立一個新的 Response
物件,其中串流為主體,然後使用 response.json()
將串流讀取到 JSON 物件中。
import { Readable } from "stream";
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
const json = await new Response(stream).json();
console.log(json); // { hello: "world" }