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

BunFile の操作の詳細については、API > ファイル I/O ドキュメントを参照してください。

Bun by www.bunjs.com.cn 編集