將 Node.js Readable 轉換為 JSON
要在 Bun 中將 Node.js 的 Readable 流轉換為 JSON 物件,請使用該流作為正文建立一個 Response,然後呼叫 response.json()。
TypeScript
import { Readable } from "stream";
const stream = Readable.from([JSON.stringify({ hello: "world" })]);
const json = await new Response(stream).json();
console.log(json); // { hello: "world" }