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
的資訊。