此代码片段将 Blob 写入磁盘上的特定路径。
它使用快速的 Bun.write() API 有效地将数据写入磁盘。第一个参数是 目标,如绝对路径或 BunFile 实例。第二个是要写入的 数据。
ts
const path = "/path/to/file.txt";
await Bun.write(path, "Lorem ipsum");BunFile 类扩展了 Blob,因此你也可以直接将 BunFile 传递给 Bun.write()。
ts
const path = "./out.txt";
const data = Bun.file("./in.txt");
// 将 ./in.txt 的内容写入 ./out.txt
await Bun.write(path, data);请参阅 文档 > API > File I/O 获取 Bun.write() 的完整文档。