要在 Bun 中將 Node.js Readable 流轉換為 JSON 對象,你可以使用流作為 body 創建一個新的 Response 對象,然後使用 response.json() 將流讀取為 JSON 對象。
ts
import { Readable } from "stream";
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
const json = await new Response(stream).json();
console.log(json); // { hello: "world" }