From 4c89c60867591b50e0b31bf5009fd5ad6a3cebe1 Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Wed, 26 Jul 2023 14:59:39 -0700 Subject: Add files (#3826) --- docs/guides/read-file/mime.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 docs/guides/read-file/mime.md (limited to 'docs/guides/read-file/mime.md') diff --git a/docs/guides/read-file/mime.md b/docs/guides/read-file/mime.md new file mode 100644 index 000000000..44a8e6860 --- /dev/null +++ b/docs/guides/read-file/mime.md @@ -0,0 +1,20 @@ +--- +name: 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. + +```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 +``` + +--- + +Refer to [API > File I/O](/docs/api/file-io) for more information on working with `BunFile`. -- cgit v1.2.3