此代码片段将 Response 写入磁盘上的特定路径。Bun 将根据其 Content-Type 头消耗 Response 体。
它使用快速的 Bun.write() API 有效地将数据写入磁盘。第一个参数是 目标,如绝对路径或 BunFile 实例。第二个是要写入的 数据。
ts
const result = await fetch("https://bun.com");
const path = "./file.txt";
await Bun.write(path, result);请参阅 文档 > API > File I/O 获取 Bun.write() 的完整文档。