要在 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" }