Bun

指南寫入檔案

使用 Bun 將 ReadableStream 寫入檔案

若要將 ReadableStream 寫入磁碟,請先從串流建立 Response 實例。然後可以使用 Bun.write() 將此 Response 寫入磁碟。

const stream: ReadableStream = ...;
const path = "./file.txt";
const response = new Response(stream);

await Bun.write(path, response);

請參閱 文件 > API > 檔案 I/O 以取得 Bun.write() 的完整文件。