运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

获取文件的 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。