Skip to main content
要将 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" }