Skip to main content
此代码片段将 Response 写入特定路径的磁盘。Bun 将根据其 Content-Type 头来消费 [Response] 主体。 它使用快速的 Bun.write() API 高效地将数据写入磁盘。第一个参数是_目标_,比如绝对路径或 [BunFile] 实例。第二个参数是要写入的_数据_。
const result = await fetch("https://bun.com");
const path = "./file.txt";
await Bun.write(path, result);

请参阅 文档 > API > 文件 I/O 了解 Bun.write() 的完整文档。