GithubHelp home page GithubHelp logo

mime-db's Introduction

mime-db

NPM Version NPM Downloads Node.js Version Build Status Coverage Status

This is a large database of mime types and information about them. It consists of a single, public JSON file and does not include any logic, allowing it to remain as un-opinionated as possible with an API. It aggregates data from the following sources:

Installation

npm install mime-db

Database Download

If you intend to use this in a web browser, you can conveniently access the JSON file via jsDelivr, a popular CDN (Content Delivery Network). To ensure stability and compatibility, it is advisable to specify a release tag instead of using the 'master' branch. This is because the JSON file's format might change in future updates, and relying on a specific release tag will prevent potential issues arising from these changes.

https://cdn.jsdelivr.net/gh/jshttp/mime-db@master/db.json

Usage

var db = require('mime-db')

// grab data on .js files
var data = db['application/javascript']

Data Structure

The JSON file is a map lookup for lowercased mime types. Each mime type has the following properties:

  • .source - where the mime type is defined. If not set, it's probably a custom media type.
  • .extensions[] - known extensions associated with this mime type.
  • .compressible - whether a file of this type can be gzipped.
  • .charset - the default charset associated with this type, if any.

If unknown, every property could be undefined.

Contributing

The primary way to contribute to this database is by updating the data in one of the upstream sources. The database is updated from the upstreams periodically and will pull in any changes.

Registering Media Types

The best way to get new media types included in this library is to register them with the IANA. The community registration procedure is outlined in RFC 6838 section 5. Types registered with the IANA are automatically pulled into this library.

Direct Inclusion

If that is not possible / feasible, they can be added directly here as a "custom" type. To do this, it is required to have a primary source that definitively lists the media type. If an extension is going to be listed as associateed with this media type, the source must definitively link the media type and extension as well.

To edit the database, only make PRs against src/custom-types.json or src/custom-suffix.json.

The src/custom-types.json file is a JSON object with the MIME type as the keys and the values being an object with the following keys:

  • compressible - leave out if you don't know, otherwise true/false to indicate whether the data represented by the type is typically compressible.
  • extensions - include an array of file extensions that are associated with the type.
  • notes - human-readable notes about the type, typically what the type is.
  • sources - include an array of URLs of where the MIME type and the associated extensions are sourced from. This needs to be a primary source; links to type aggregating sites and Wikipedia are not acceptable.

To update the build, run npm run build.

mime-db's People

Contributors

alrra avatar barraq avatar billiegoose avatar broofa avatar carpasse avatar commanderroot avatar dougwilson avatar howardroark avatar jhermsmeier avatar jonathanong avatar mathiasbynens avatar mrdoob avatar nbougalis avatar nfroidure avatar paulofreitas avatar peterdavehello avatar pheyvaer avatar pthong avatar ralfhandl avatar reecefenwick avatar rhodgkins avatar rmzelle avatar ronanww avatar rubenverborgh avatar sampathkumarkrishnan avatar snuggs avatar tannewt avatar thardeck avatar tinhochu avatar xiaohanyu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mime-db's Issues

Remove compressible for db 2.0

Since we defined the 1.0 of the mime-db it has worked well, expect for one of the properties: compressible. This property cannot be derived from the upstream data and instead rules must live in this repo to populate the value. By itself, this is not too bad, but it adds additional complexity to the module as well as inflates the size of the database for something many may not even use.

I'm thinking that a 2.0 version should drop this property from the database format and all related rules from this module.

The compressible data and ruleset would live on still, under the npm module compressible. Instead of delegating to this module for compressible data, it would instead be the store of all the rules (and would not even need to depend on this module).

I'm opening this up for thoughts on this proposal, especially for those who are dependent on the database format. I'm not planning to make any changes for quite some time. Perhaps in a few months at the earliest, so there is plenty of time for feedback to fall here, if any.

Compressible for image/svg+xml?

This seems to a tricky issue.

Mime type image/svg+xml has svg and svgz listed, and is marked compressible.

svg is plain text is expectedly compressible. However, svgz is already zip compressed format and should be not compressible.

Suggestion: add perceived type

Friendly suggestion to add perceived type to each mime type. This would make it easier to distinguish between types of media such as video, audio, graphics, text, etc. The first part of a mime type is not always the deciding factor, after all. Plus there are agnostic mime groups, like application.

Perhaps perceived type could be left out when the mime group makes it clear by itself.

Cannot find module './db.json'

I'm getting this error and no matter what I do I can't get rid of it.

I'm using typescript v2.3.4
node v7.8.0 (though seeing the same issue with 7.4.0)
and my tsconfig is:

{
 "compilerOptions": {
   "alwaysStrict": true,
   "outDir": "built",
   "lib": [ "es6" ],
   	"module": "commonjs",
   	"target": "es6",
   "pretty": true,
   "removeComments": true,
   	"sourceMap": true
 },
 "include": [
     "src/**/*"
 ],
 "exclude": [
   "node_modules"
 ]
}

I've ran npm cache clean and re-installed all my node modules.
If I delete my generated built folder and run the code, everything works as expected but when I run it again, I get the above error. Any ideas?

mime type for .csv files can be reported incorrectly under specific conditions

By default mime type for .csv files should be text/csv. However in case when target OS is MS Windows and MS Office is also installed on that system mime type for that file will be application/vnd.ms-excel

I was able to reproduce this issue on Win 8 and Win 10 and latest MS Office. Also I have found few links where sames issue or issues based on this are discussed

I do not know right way how we should go with this, but I am sure we need a place where all bits on this issue will be gathered together

upd

win10+office2016

win10 office2016


win10+libreoffice

title10

source.md from mime-types

Sources for custom types

This is a list of sources for any custom mime types.
When adding custom mime types, please link to where you found the mime type,
even if it's from an unofficial source.

Sources for node.json types

Notes on weird types

  • font/opentype - This type is technically invalid according to the spec. No valid types begin with font/. No-one uses the official type of application/vnd.ms-opentype as the community standardized application/x-font-otf. However, chrome logs nonsense warnings unless opentype fonts are served with font/opentype. [1]

Better way to manage extension priority for multiple types

We need a better way to manage extension priority for multiple types (i.e. provide an extension -> mime mapping).

The reason we need this is because as we source from more places, you cannot just build this mapping in other libraries by iterating over the types and just accumulating the extensions in a map, as they may not be in the most optimal order.

Worth to add nginx mime.types

You may know that nginx another wide popular proxy server, and it has own mime.types db.
That is nearest link. It is short but for some mime types it has additional extenisions.

wanting to add a type

I wish to add a type for .sha256 extensions (and perhaps other cyphers). Any thoughts?

Just started getting build errors in mime-db

nodemon /.../server.js -debug -e json,js

SyntaxError: /.../node_modules/express/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/node_modules/mime-db/db.json: Unexpected token v
    at Object.parse (native)
    at Object.Module._extensions..json (module.js:482:27)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/.../node_modules/express/node_modules/connect/node_modules/errorhandler/node_modules/accepts/node_modules/mime-types/node_modules/mime-db/index.js:11:18)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

Define .php files as text/html not application/x-httpd-php

GitHub Pages uses mime-db to decide what content type to use when serving static files. This means that a static file named "index.php" will be served with the MIME type "application/x-httpd-php" which makes the browser download the file instead of interpreting it. This makes it impossible for an existing web site, which happened to use PHP pages and ".php" extensions in its URLs, to migrate to GitHub Pages, without making all old links non-functional.

I suggest you change the MIME type for .php files to "text/html". This will make it possible for existing projects moving to GitHub Pages to preserve their existing URLs by creating static HTML files whose names match the old .php pages.

I initially reported this problem to GitHub Pages, and they directed me to file an issue here instead.

review

before i release 1.0.0.

@hueniverse: if this looks good to you, i'll add you (and whoever else) as owner as well

Add extensions for obsolete mimetypes

Sometimes we'd want to lookup a file extension from a given mimetype. For example, we want to get "js" if we are given a mimetype "text/javascript". This is currently not possible since the "extensions" key for "text/javascript" is not defined.

I'd suggest that we define an obsolete mimetype, such as "text/javascript", like this:

"text/javascript": {
  "source": "iana",
  "compressible": true,
  "obsolete": true,
  "extensions": ["js"]
},

So that the application is able to get an extension when "text/javascript" is given. If the application wants to reversely look for the mimetype for "js", it can ignore the "text/javascript" according to its "obsolete" value.

We can optionally add a "canonical": "application/javascript" to indicate what this obsolete mimetype is now redirected to.

mime.lookup(audiofile.mp3) get wrong mimetype and extension

filename = audiofile.mp3
mimetype: audio/mpeg
extension: mpga

temporary workaround is modify db.json (see below)

before:
"audio/mpeg": {
"source": "iana",
"compressible": false,
"extensions": ["mpga","mp2","mp2a","mp3","m2a","m3a"]

after:
"audio/mpeg": {
"source": "iana",
"compressible": false,
"extensions": ["mp3","mpga","mp2","mp2a","m2a","m3a"]

waiting your feedback.

Regards,
Giuseppe

98

KALML

Move jpg to the first index of image/jpeg extensions array

Before:

  "image/jpeg": {
    "extensions": ["jpeg","jpg"]
  },

After:

  "image/jpeg": {
    "extensions": ["jpg","jpeg"]
  },

Why?

mime-types module has an .extension(type) method that returns first extension in this array, which is the horrible and ugly jpeg that none prefers over jpg, so I always have to do:

let ext = mime.extension(type);
if (ext === 'jpeg') ext = 'jpg';

Or modify the extensions array at the start of my app (effectively detaching it from the affected code), than forgetting I did that, move to another project, and have to debug why are my files .jpegs again.

In general it would be great to move the preferred extension in each extensions array to its 1st index. But this one is the one that will solve 99% of the frustrating "not a preferred extension" encounters.

It's just another one of those paper cuts that kill the joy of programming.

Provisional Standard Media Type Registry

Hi there. Thanks for this great project.

I did have a question however. Currently image/jxr is sitting in "limbo" at IANA however it is actively being used in Windows 10 Edge browsers. Our site has received a few of these requests already.

It is also my understanding that the .jxr extension Media Type (MIME for us more tenured folks) used to be image/vnd.ms-photo from a few reads throughout the internet.

My questions are fairly simple... are those PSMTR entries considered when making the database? Should they be?

Thanks so much.

can't install v1.14.0 via npm

Looks like this package is released at version v1.14.0 on npm but when i install it via npm install mime-db I get v1.13.0

Suggestion: reverse map for extension lookup

One thing that would be nice would be a way to go from extension to mime-type(s), encoding, compressing info, etc. Perhaps it could be generated as a second file in your build step.

This project is a great idea, well done.

Magic numbers

Are there any plans to add magic number support to deduce the mime-type for a Buffer?
e.g. "ff d8 ff e0" for "image/jpeg"

woff and woff2

"application/font-woff":["woff"],"application/font-woff2":["woff2"],

is

"font/woff":["woff"],"font/woff2":["woff2"],

Proof example:

  • wget -v https://fonts.gstatic.com/s/roboto/v16/ek4gzZ-GeXAPcSbHtCeQI_esZW2xOQ-xsNqO47m55DA.woff2

Mime type for .tar.gz and .tgz?

Hello,

I was wondering if the mentioned file extensions are going to be supported at some point. After checking around the recommended mime type for them is application/gzip but I might be wrong.

Looking forward to any feedback

font/woff for woff font

Hi.

I havs small application that proxy pages (basically download pages and associated resources) and i noticed that some sites return woff fonts with font/woff, i did not notice this module has this content-type.

binary/text flags

would be nice, especially for mime types that aren't text/. i want to know if i could treat a file as a string. might be able to get rid of charset as well.

UTF-8 charset by default on "text/html"

Hi,
In the 21st century, UTF-8 became de facto the standard for www.
In order to not overwrite thousands of http-server, it's enough to change "text/html" to "text/html;charset=UTF-8" in mime-types by default.
This does not change the work of old html-documents in any way, but instantly includes the correct display of many-many new languages.

"text/html;charset=UTF-8": {
    "source": "iana",
    "compressible": true,
    "extensions": ["html","htm","shtml"]
}

Add common name?

Thoughts about adding a property like commonName that provides a short, commonly used label for certain types?

e.g.
text/calendar is commonly known as iCalendar.

This is coming up for me because I am building an app that displays file types as a dropdown list for end users.

Various wrong mime types

The code to read from the IANA database is using the template file link's name to determine the mime type; this is not always the same. Example is basically all the MIME type entries we have that contains vnd- instead of vnd.

Issue in loading WOFF fonts in Express JS

Hi,

I was facing issue in loading WOFF fonts while using Ionicons icon-font in my Express.js + Node application.

After some investigation I have found that either we need to update or add new entry for WOFF fonts in DB.json file as given below at line no 370.

application/x-font-woff

db.json line no 370: "application/x-font-woff"

Ref URL : http://stackoverflow.com/questions/3594823/mime-type-for-woff-fonts

I hope this will be helpful.

Thanks,
Jignesh Raval

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.