运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

将 Node.js Readable 转换为字符串

要在 Bun 中将 Node.js Readable 流转换为字符串,请使用该流作为正文创建一个 Response,然后调用 response.text()。

TypeScript
import { Readable } from "stream";
const stream = Readable.from([Buffer.from("Hello, world!")]);
const text = await new Response(stream).text();
console.log(text); // "你好,世界!"