Skip to content

Bun.file() 函數接受一個路徑並返回一個 BunFile 實例。BunFile 類擴展了 Blob,所以使用 .type 屬性讀取 MIME 類型。

ts
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 的更多信息。

Bun學習網由www.bunjs.com.cn整理維護