此代碼片段將 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() 的完整文檔。