Skip to content
This repository
Newer
Older
100644 67 lines (39 sloc) 2.235 kb
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
1 # mime
2
68f653f0 »
2012-02-16 patchup README and #24
3 Comprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
4
5 ## Install
6
7 Install with [npm](http://github.com/isaacs/npm):
8
9 npm install mime
10
c1cda0be »
2011-09-06 some doc cleanup, putting 'buffer' type back in
11 ## API - Queries
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
12
7a7fa3be »
2011-09-05 Added comments to node.types providing rational (or lack thereof) for…
13 ### mime.lookup(path)
1107bca8 »
2013-03-18 added note about default mime type
14 Get the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
55f8dded »
2010-02-24 Add readme
15
16 var mime = require('mime');
17
5712bec4 »
2010-09-16 update readme
18 mime.lookup('/path/to/file.txt'); // => 'text/plain'
19 mime.lookup('file.txt'); // => 'text/plain'
68f653f0 »
2012-02-16 patchup README and #24
20 mime.lookup('.TXT'); // => 'text/plain'
5712bec4 »
2010-09-16 update readme
21 mime.lookup('htm'); // => 'text/html'
55f8dded »
2010-02-24 Add readme
22
1107bca8 »
2013-03-18 added note about default mime type
23 ### mime.default_type
077e41c2 »
2013-07-25 update mime.types file, add check for duplicate definitions between n…
24 Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
1107bca8 »
2013-03-18 added note about default mime type
25
68f653f0 »
2012-02-16 patchup README and #24
26 ### mime.extension(type)
27 Get the default extension for `type`
55f8dded »
2010-02-24 Add readme
28
12a5ecdb »
2010-09-16 Simplify extension parsing. Fix readme typo
29 mime.extension('text/html'); // => 'html'
8a03ecc7 »
2011-01-20 buffer -> bin
30 mime.extension('application/octet-stream'); // => 'bin'
accd8862 »
2011-01-20 Cleaned up file parsing code
31
68f653f0 »
2012-02-16 patchup README and #24
32 ### mime.charsets.lookup()
33
34 Map mime-type to charset
accd8862 »
2011-01-20 Cleaned up file parsing code
35
2fac06b2 »
2011-01-25 Fixed typo in README.md
36 mime.charsets.lookup('text/plain'); // => 'UTF-8'
55f8dded »
2010-02-24 Add readme
37
8b9799ea »
2011-01-26 update readme
38 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
55f8dded »
2010-02-24 Add readme
39
68f653f0 »
2012-02-16 patchup README and #24
40 ## API - Defining Custom Types
6b8b5a0c »
2010-10-06 Update README with how to install
41
8f37fe89 »
2012-07-14 New wiki location, /broofa/
42 The following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).
68f653f0 »
2012-02-16 patchup README and #24
43
44 ### mime.define()
45
46 Add custom mime/extension mappings
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
47
48 mime.define({
49 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
50 'application/x-my-type': ['x-mt', 'x-mtt'],
51 // etc ...
52 });
53
54 mime.lookup('x-sft'); // => 'text/x-some-format'
68f653f0 »
2012-02-16 patchup README and #24
55
56 The first entry in the extensions array is returned by `mime.extension()`. E.g.
57
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
58 mime.extension('text/x-some-format'); // => 'x-sf'
59
68f653f0 »
2012-02-16 patchup README and #24
60 ### mime.load(filepath)
61
62 Load mappings from an Apache ".types" format file
46e7c079 »
2011-01-20 Added mime#define to allow programatic type declaration
63
64 mime.load('./my_project.types');
68f653f0 »
2012-02-16 patchup README and #24
65
66 The .types file format is simple - See the `types` dir for examples.
Something went wrong with that request. Please try again.