Bun.file() 函數接受一個路徑並返回一個 BunFile 實例。BunFile 類擴展了 Blob,允許你以多種格式延遲讀取文件。使用 .text() 將內容讀取為字符串。
ts
const path = "/path/to/file.txt";
const file = Bun.file(path);
const text = await file.text();
// string任何相對路徑都將相對於項目根目錄(包含 package.json 文件的最近目錄)解析。
ts
const path = "./file.txt";
const file = Bun.file(path);