這段程式碼片段會將 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);
請參閱 文件 > API > 檔案 I/O 以取得 Bun.write()
的完整文件。