]> git.cworth.org Git - obsolete/notmuch-web/blob - node_modules/express/node_modules/mime/README.md
Install the "express" node module via npm
[obsolete/notmuch-web] / node_modules / express / node_modules / mime / README.md
1 # mime
2
3 Support for mapping between file extensions and MIME types.  This module uses the latest version of the Apache "mime.types" file (maps over 620 types to 800+ extensions).  It is also trivially easy to add your own types and extensions, should you need to do that.
4
5 ## Install
6
7 Install with [npm](http://github.com/isaacs/npm):
8
9     npm install mime
10
11 ## API
12
13 ### mime.lookup(path) - lookup the type for a file or extension
14
15     var mime = require('mime');
16
17     mime.lookup('/path/to/file.txt');         // => 'text/plain'
18     mime.lookup('file.txt');                  // => 'text/plain'
19     mime.lookup('.txt');                      // => 'text/plain'
20     mime.lookup('htm');                       // => 'text/html'
21
22 ### mime.extension(type) - lookup the default extension for type
23
24     mime.extension('text/html');                 // => 'html'
25     mime.extension('application/octet-stream');  // => 'bin'
26
27 ### mime.charsets.lookup() - map mime-type to charset
28
29     mime.charsets.lookup('text/plain');        // => 'UTF-8'
30
31 (The logic for charset lookups is pretty rudimentary.  Feel free to suggest improvements.)
32
33 ## "Can you add support for [some type/extension]?"
34
35 Start by adding support for the type in your project using the mime.define() or mime.load() methods (documented below).
36
37 If there's a type that is shared across node.js modules, by different people, create an issue here and we'll add it if it makes sense.
38
39 If the type in question applies to projects outside the node.js community (e.g. if [IANA](http://www.iana.org/assignments/media-types/) approves a new type) file a [bug with Apache](http://httpd.apache.org/bug_report.html) and create an issue here that links to it.
40
41 ### mime.define() - Add custom mime/extension mappings
42
43     mime.define({
44         'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
45         'application/x-my-type': ['x-mt', 'x-mtt'],
46         // etc ...
47     });
48
49     mime.lookup('x-sft');                 // => 'text/x-some-format'
50     mime.extension('text/x-some-format'); // => 'x-sf'
51
52 ### mime.load(filepath) - Load mappings from an Apache ".types" format file
53
54     mime.load('./my_project.types');