Skip to main content
此代码片段将 Blob 写入特定路径的磁盘。 它使用快速的 Bun.write() API 高效地将数据写入磁盘。第一个参数是_目标_,比如绝对路径或 [BunFile] 实例。第二个参数是要写入的_数据_。
const path = "/path/to/file.txt";
await Bun.write(path, "Lorem ipsum");

[BunFile] 类扩展了 Blob,所以您也可以直接将 [BunFile] 传递给 Bun.write()
const path = "./out.txt";
const data = Bun.file("./in.txt");

// 将 ./in.txt 的内容写入 ./out.txt
await Bun.write(path, data);

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