將檔案作為字串讀取
Bun.file() 函式接受一個路徑並傳回一個 BunFile 例項。BunFile 擴充套件自 Blob,因此你可以使用多種格式延遲讀取檔案。使用 .text() 將內容讀取為字串。
TypeScript
const path = "/path/to/file.txt";
const file = Bun.file(path);
const text = await file.text();
// 字串
Bun 從當前工作目錄解析相對路徑。
TypeScript
const path = "./file.txt";
const file = Bun.file(path);