Bun Get the MIME type of a file

Get the MIME type of a file

jarle Updated

File contents

Get the MIME type of a file

The Bun.file() function accepts a path and returns a BunFile instance. The BunFile class extends Blob, so use the .type property to read the MIME type.

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

Refer to API > File I/O for more information on working with BunFile.

jarle/bun-skills/tree/main/skills/bun-guides-read-file-mime commit eb2ecbd2cc

Frequently asked questions

npx skillmds@latest add jarle/bun-get-the-mime-type-of-a-file