Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 64 lines (37 sloc) 2.017 kB
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
1 # mime
2
68f653f @broofa patchup README and #24
authored
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.
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
4
5 ## Install
6
7 Install with [npm](http://github.com/isaacs/npm):
8
9 npm install mime
10
c1cda0b @broofa some doc cleanup, putting 'buffer' type back in
authored
11 ## API - Queries
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
12
7a7fa3b @broofa Added comments to node.types providing rational (or lack thereof) for…
authored
13 ### mime.lookup(path)
68f653f @broofa patchup README and #24
authored
14 Get the mime type associated with a file. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
55f8dde Add readme
Benjamin Thomas authored
15
16 var mime = require('mime');
17
5712bec @broofa update readme
authored
18 mime.lookup('/path/to/file.txt'); // => 'text/plain'
19 mime.lookup('file.txt'); // => 'text/plain'
68f653f @broofa patchup README and #24
authored
20 mime.lookup('.TXT'); // => 'text/plain'
5712bec @broofa update readme
authored
21 mime.lookup('htm'); // => 'text/html'
55f8dde Add readme
Benjamin Thomas authored
22
68f653f @broofa patchup README and #24
authored
23 ### mime.extension(type)
24 Get the default extension for `type`
55f8dde Add readme
Benjamin Thomas authored
25
12a5ecd @broofa Simplify extension parsing. Fix readme typo
authored
26 mime.extension('text/html'); // => 'html'
8a03ecc @broofa buffer -> bin
authored
27 mime.extension('application/octet-stream'); // => 'bin'
accd886 @broofa Cleaned up file parsing code
authored
28
68f653f @broofa patchup README and #24
authored
29 ### mime.charsets.lookup()
30
31 Map mime-type to charset
accd886 @broofa Cleaned up file parsing code
authored
32
2fac06b @shfx Fixed typo in README.md
shfx authored
33 mime.charsets.lookup('text/plain'); // => 'UTF-8'
55f8dde Add readme
Benjamin Thomas authored
34
8b9799e @broofa update readme
authored
35 (The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
55f8dde Add readme
Benjamin Thomas authored
36
68f653f @broofa patchup README and #24
authored
37 ## API - Defining Custom Types
6b8b5a0 Update README with how to install
Benjamin Thomas authored
38
8f37fe8 @joelpurra New wiki location, /broofa/
joelpurra authored
39 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).
68f653f @broofa patchup README and #24
authored
40
41 ### mime.define()
42
43 Add custom mime/extension mappings
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
44
45 mime.define({
46 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
47 'application/x-my-type': ['x-mt', 'x-mtt'],
48 // etc ...
49 });
50
51 mime.lookup('x-sft'); // => 'text/x-some-format'
68f653f @broofa patchup README and #24
authored
52
53 The first entry in the extensions array is returned by `mime.extension()`. E.g.
54
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
55 mime.extension('text/x-some-format'); // => 'x-sf'
56
68f653f @broofa patchup README and #24
authored
57 ### mime.load(filepath)
58
59 Load mappings from an Apache ".types" format file
46e7c07 @broofa Added mime#define to allow programatic type declaration
authored
60
61 mime.load('./my_project.types');
68f653f @broofa patchup README and #24
authored
62
63 The .types file format is simple - See the `types` dir for examples.
Something went wrong with that request. Please try again.