此程式碼片段將一個 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");
// write the contents of ./in.txt to ./out.txt
await Bun.write(path, data);
有關 Bun.write() 的完整文件,請參閱 文件 > API > 檔案 I/O。