執行環境套件管理器打包器測試執行器程式碼檢查格式化指南參考部落格意見回饋

獲取檔案的 MIME 型別

Bun.file() 函式接受一個路徑並傳回一個 BunFile 例項。BunFile 類繼承自 Blob,因此可以使用 .type 屬性讀取 MIME 型別。

TypeScript
const file = Bun.file("./package.json");
file.type; // application/json;charset=utf-8

const html = Bun.file("./index.html");
html.type; // text/html;charset=utf-8

const image = Bun.file("./image.png");
image.type; // image/png

有關如何使用 BunFile 的更多資訊,請參閱檔案 I/O。