|
| 1 | +# 💁 mime-db-cdn |
| 2 | +CDN-compatible version of [mime-db](https://github.com/jshttp/mime-db). |
| 3 | + |
| 4 | +## Why this project? |
| 5 | +[mime-db](https://github.com/jshttp/mime-db) managed to stay un-opinionated about an API by packing the entire MIME-type database into a [JSON file](https://github.com/jshttp/mime-db/blob/master/db.json). Using `mime-db` directly, therefore, entails downloading the entire database at once, albeit from a CDN. If you just need to query a handful of MIME-types or file-extensions, downloading the entire database followed by loading and retaining it in memory would be an overkill. This problem persists with popular opinionated APIs based on `mime-db`, such as [mime](https://www.npmjs.com/package/mime) or [mime-types](https://www.npmjs.com/package/mime-types), which must first store the entire database locally on the user's machine in order to function. |
| 6 | + |
| 7 | +The current project solves this problem by fragmenting `mime-db` into tiny files, each storing data only for one of the available MIME-types or file-extensions. To understand the file-structure, explore the directories in the [database branch](https://github.com/SomajitDey/mime-db-cdn/tree/database). Each of these files is readily downloadable using any of the free CDNs that serve GitHub contents, e.g. |
| 8 | +- [jsdelivr](https://www.jsdelivr.com/?docs=gh) |
| 9 | +- [statically](https://github.com/staticallyio/statically) |
| 10 | +- [raw.githack](https://raw.githack.com/) |
| 11 | + |
| 12 | +or even using |
| 13 | +- `https://raw.githubusercontents.com/somajitdey/mime-db-cdn/database/<path>` |
| 14 | + |
| 15 | +## Usage |
| 16 | + |
| 17 | +### MIME-type to file-extension(s) |
| 18 | +Download from CDN as JSON: |
| 19 | +``` |
| 20 | +https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@database/mime-types/<mime-type>/data.json |
| 21 | +``` |
| 22 | +replace `<mime-type>` with your chosen MIME-type e.g. `image/jpeg`. |
| 23 | + |
| 24 | +### File-extension to MIME-type(s) |
| 25 | +Download from CDN: |
| 26 | +``` |
| 27 | +https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@database/extensions/type.<extension> |
| 28 | +``` |
| 29 | +replace `<extension>` with your chosen extension e.g. `jpg`. |
| 30 | + |
| 31 | +👉 The `Content-Type` header from the CDN's http-response might contain the desired MIME-type, as provided by the CDN provider. |
| 32 | + |
| 33 | +👉 However, we recommend using the textual data contained within the response's body, formatted as one MIME-type per line, as it is taken from the [mime-db](https://github.com/jshttp/mime-db). |
| 34 | + |
| 35 | +👉 To download the data with `Content-Type: text/plain` http-response-header use: |
| 36 | + |
| 37 | +``` |
| 38 | +https://raw.githubusercontents.com/somajitdey/mime-db-cdn/database/extensions/type.<extension> |
| 39 | +``` |
| 40 | + |
| 41 | +### Examples |
| 42 | +The database may be found at branch [database](https://github.com/SomajitDey/mime-db-cdn/tree/database) or any of the [tags](https://github.com/SomajitDey/mime-db-cdn/tags) that has a [release with the same name in mime-db](https://github.com/jshttp/mime-db/tags). |
| 43 | + |
| 44 | +👉 In production, it is recommended to use a specific [tag](https://github.com/SomajitDey/mime-db-cdn/tags) instead of the `database` string in the CDN URLs provided above. |
| 45 | + |
| 46 | +For example, to download the MIME-type for `image/jpeg` from [mime-db release v1.54.0](https://github.com/jshttp/mime-db/releases/tag/v1.54.0), use CDN: |
| 47 | + |
| 48 | +https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@v1.54.0/mime-types/image/jpeg/data.json |
| 49 | + |
| 50 | +To get the MIME-type corresponding to `.mjs`, use CDN: |
| 51 | + |
| 52 | +https://cdn.jsdelivr.net/gh/somajitdey/mime-db-cdn@v1.54.0/extensions/type.mjs |
| 53 | + |
| 54 | +## Reliability of this database |
| 55 | +The upstream [mime-db](https://github.com/jshttp/mime-db) is [checked hourly for updates](https://github.com/SomajitDey/mime-db-cdn/actions). If a new release is available upstream, [this database](https://github.com/SomajitDey/mime-db-cdn/tree/database) is built afresh from that release and a new [git-tag](https://github.com/SomajitDey/mime-db-cdn/tags) is released with the same name as the [latest mime-db release](https://github.com/jshttp/mime-db/releases). |
| 56 | + |
| 57 | +# Contribute |
| 58 | +To register new media types in the database [contribute directly to mime-db](https://github.com/jshttp/mime-db#contributing). |
| 59 | + |
| 60 | +If you like this project, you can show your appreciation by |
| 61 | +- [giving it a star](https://github.com/SomajitDey/mime-db-cdn/stargazers) ⭐ |
| 62 | +- sponsoring me through 👇 |
| 63 | + |
| 64 | +[](https://buymeacoffee.com/SomajitDey) |
| 65 | + |
| 66 | +Thank you 💚. |
0 commit comments