Bun.file()
函數接受路徑並傳回 BunFile
實例。BunFile
類別擴展了 Blob
,讓您可以延遲讀取各種格式的檔案。使用 .json()
讀取並解析 .json
檔案的內容為純物件。
BunFile
的 MIME 類型將會相應地設定。
const path = "/path/to/package.json";
const file = Bun.file(path);
const contents = await file.json();
// { name: "my-package" }
file.type; // => "application/json;charset=utf-8";