Bun.file()
函數接受路徑並返回 BunFile
實例。BunFile
類別擴展了 Blob
,因此請使用 .type
屬性來讀取 MIME 類型。
const file = Bun.file("./package.json");
file.type; // application/json
const file = Bun.file("./index.html");
file.type; // text/html
const file = Bun.file("./image.png");
file.type; // image/png
請參閱API > 檔案 I/O 以取得更多關於使用 BunFile
的資訊。