Skip to content

Commit

Permalink
src from nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Feb 9, 2015
1 parent ca3a854 commit 7315783
Show file tree
Hide file tree
Showing 6 changed files with 340 additions and 11 deletions.
17 changes: 17 additions & 0 deletions HISTORY.md
@@ -1,3 +1,20 @@
unreleased
==========

* Add nginx as a source
* Add `application/x-cocoa`
* Add `application/x-java-archive-diff`
* Add `application/x-makeself`
* Add `application/x-perl`
* Add `application/x-pilot`
* Add `application/x-redhat-package-manager`
* Add `application/x-sea`
* Add `audio/x-m4a`
* Add `audio/x-realaudio`
* Add `image/x-jng`
* Add `image/x-ms-bmp`
* Add `text/mathml`

1.6.0 / 2015-01-29
==================

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -13,6 +13,7 @@ It aggregates data from the following sources:

- http://www.iana.org/assignments/media-types/media-types.xhtml
- http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
- http://hg.nginx.org/nginx/raw-file/default/conf/mime.types

## Usage

Expand Down Expand Up @@ -43,6 +44,7 @@ Each mime type has the following properties:
If not set, it's probably a custom media type.
- `apache` - [Apache common media types](http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types)
- `iana` - [IANA-defined media types](http://www.iana.org/assignments/media-types/media-types.xhtml)
- `nginx` - [nginx media types](http://hg.nginx.org/nginx/raw-file/default/conf/mime.types)
- `.extensions[]` - known extensions associated with this mime type.
- `.compressible` - whether a file of this type is can be gzipped.
- `.charset` - the default charset associated with this type, if any.
Expand Down
64 changes: 57 additions & 7 deletions db.json
Expand Up @@ -410,7 +410,7 @@
"application/java-archive": {
"source": "apache",
"compressible": false,
"extensions": ["jar"]
"extensions": ["jar","war","ear"]
},
"application/java-serialized-object": {
"source": "apache",
Expand Down Expand Up @@ -684,7 +684,7 @@
"application/octet-stream": {
"source": "iana",
"compressible": false,
"extensions": ["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","buffer"]
"extensions": ["bin","dms","lrf","mar","so","dist","distz","pkg","bpk","dump","elc","deploy","msi","msp","msm","buffer"]
},
"application/oda": {
"source": "iana",
Expand Down Expand Up @@ -4093,6 +4093,10 @@
"application/x-chrome-extension": {
"extensions": ["crx"]
},
"application/x-cocoa": {
"source": "nginx",
"extensions": ["cco"]
},
"application/x-compress": {
"source": "apache"
},
Expand Down Expand Up @@ -4247,6 +4251,10 @@
"source": "apache",
"extensions": ["iso"]
},
"application/x-java-archive-diff": {
"source": "nginx",
"extensions": ["jardiff"]
},
"application/x-java-jnlp-file": {
"source": "apache",
"compressible": false,
Expand All @@ -4267,6 +4275,10 @@
"source": "apache",
"extensions": ["lzh","lha"]
},
"application/x-makeself": {
"source": "nginx",
"extensions": ["run"]
},
"application/x-mie": {
"source": "apache",
"extensions": ["mie"]
Expand Down Expand Up @@ -4354,6 +4366,14 @@
"source": "apache",
"extensions": ["nzb"]
},
"application/x-perl": {
"source": "nginx",
"extensions": ["pl","pm"]
},
"application/x-pilot": {
"source": "nginx",
"extensions": ["prc","pdb"]
},
"application/x-pkcs12": {
"source": "apache",
"compressible": false,
Expand All @@ -4372,10 +4392,18 @@
"compressible": false,
"extensions": ["rar"]
},
"application/x-redhat-package-manager": {
"source": "nginx",
"extensions": ["rpm"]
},
"application/x-research-info-systems": {
"source": "apache",
"extensions": ["ris"]
},
"application/x-sea": {
"source": "nginx",
"extensions": ["sea"]
},
"application/x-sh": {
"source": "apache",
"compressible": true,
Expand Down Expand Up @@ -4434,7 +4462,7 @@
},
"application/x-tcl": {
"source": "apache",
"extensions": ["tcl"]
"extensions": ["tcl","tk"]
},
"application/x-tex": {
"source": "apache",
Expand Down Expand Up @@ -4470,7 +4498,7 @@
},
"application/x-x509-ca-cert": {
"source": "apache",
"extensions": ["der","crt"]
"extensions": ["der","crt","pem"]
},
"application/x-xfig": {
"source": "apache",
Expand Down Expand Up @@ -5088,6 +5116,10 @@
"source": "apache",
"extensions": ["flac"]
},
"audio/x-m4a": {
"source": "nginx",
"extensions": ["m4a"]
},
"audio/x-matroska": {
"source": "apache",
"extensions": ["mka"]
Expand All @@ -5112,6 +5144,10 @@
"source": "apache",
"extensions": ["rmp"]
},
"audio/x-realaudio": {
"source": "nginx",
"extensions": ["ra"]
},
"audio/x-tta": {
"source": "apache"
},
Expand Down Expand Up @@ -5364,10 +5400,18 @@
"compressible": true,
"extensions": ["ico"]
},
"image/x-jng": {
"source": "nginx",
"extensions": ["jng"]
},
"image/x-mrsid-image": {
"source": "apache",
"extensions": ["sid"]
},
"image/x-ms-bmp": {
"source": "nginx",
"extensions": ["bmp"]
},
"image/x-pcx": {
"source": "apache",
"extensions": ["pcx"]
Expand Down Expand Up @@ -5673,7 +5717,7 @@
"text/html": {
"source": "iana",
"compressible": true,
"extensions": ["html","htm"]
"extensions": ["html","htm","shtml"]
},
"text/jade": {
"extensions": ["jade"]
Expand All @@ -5695,6 +5739,10 @@
"text/markdown": {
"source": "iana"
},
"text/mathml": {
"source": "nginx",
"extensions": ["mml"]
},
"text/mizar": {
"source": "iana"
},
Expand Down Expand Up @@ -5900,6 +5948,7 @@
"extensions": ["c","cc","cxx","cpp","h","hh","dic"]
},
"text/x-component": {
"source": "nginx",
"extensions": ["htc"]
},
"text/x-fortran": {
Expand Down Expand Up @@ -5966,7 +6015,8 @@
},
"text/xml": {
"source": "iana",
"compressible": true
"compressible": true,
"extensions": ["xml"]
},
"text/xml-external-parsed-entity": {
"source": "iana"
Expand All @@ -5979,7 +6029,7 @@
},
"video/3gpp": {
"source": "apache",
"extensions": ["3gp"]
"extensions": ["3gp","3gpp"]
},
"video/3gpp-tt": {
"source": "apache"
Expand Down
32 changes: 30 additions & 2 deletions scripts/build.js
Expand Up @@ -15,7 +15,22 @@ Object.keys(mime).forEach(function (type) {
var d = mime[type]
var t = type.toLowerCase()
var o = db[t] = db[t] || {source: 'apache'}
if (d.extensions && d.extensions.length) o.extensions = (o.extensions || []).concat(d.extensions)
if (d.extensions && d.extensions.length) {
o.extensions = o.extensions || []
addExtensions(o.extensions, d.extensions)
}
})

// add the mime extensions from nginx
var mime = require('../src/nginx.json')
Object.keys(mime).forEach(function (type) {
var d = mime[type]
var t = type.toLowerCase()
var o = db[t] = db[t] || {source: 'nginx'}
if (d.extensions && d.extensions.length) {
o.extensions = o.extensions || []
addExtensions(o.extensions, d.extensions)
}
})

// add all of node mime's mime extensions
Expand All @@ -25,7 +40,10 @@ Object.keys(mime).forEach(function (type) {
var d = mime[type]
var t = type.toLowerCase()
var o = db[t] = db[t] || {}
if (d.extensions && d.extensions.length) o.extensions = (o.extensions || []).concat(d.extensions)
if (d.extensions && d.extensions.length) {
o.extensions = o.extensions || []
addExtensions(o.extensions, d.extensions)
}
})

// now add all our custom extensions
Expand Down Expand Up @@ -64,3 +82,13 @@ Object.keys(charsets).forEach(function (name) {

// write db
require('./lib/write-db')('db.json', db)

function addExtensions(dest, src) {console.dir(arguments);
for (var i = 0; i < src.length; i++) {
var ext = src[i]

if (dest.indexOf(ext) === -1) {
dest.push(ext)
}
}
}
9 changes: 7 additions & 2 deletions scripts/extensions.js
Expand Up @@ -11,6 +11,7 @@ var writedb = require('./lib/write-db')
co(function* () {
yield [
get('apache', 'http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types'),
get('nginx', 'http://hg.nginx.org/nginx/raw-file/default/conf/mime.types'),
get('node', 'https://raw.githubusercontent.com/broofa/node-mime/master/types/node.types')
]
}).then()
Expand All @@ -31,12 +32,16 @@ function* get(name, url) {
*
* <type> <ext> <ext> <ext>
*
* or
*
* <type> <ext> <ext> <ext>;
*
* And some are commented out with a leading `#` because they have no associated extensions.
* This regexp checks whether a single line matches this format, ignoring lines that are just comments.
* We could also just remove all lines that start with `#` if we want to make the JSON files smaller
* and ignore all mime types without associated extensions.
*/
var re = /^(?:# )?([\w-]+\/[\w\+\.-]+)(?:\s+\w+)*$/
var re = /^(?:# )?([\w-]+\/[\w\+\.-]+)((?:\s+\w+)*);?$/
text = text.split('\n')
.filter(Boolean)
.forEach(function (line) {
Expand All @@ -47,7 +52,7 @@ function* get(name, url) {
var mime = match[1]
if (mime.substr(-8) === '/example') return
// remove the leading # and <type> and return all the <ext>s
var extensions = line.replace(/^(?:# )?([\w-]+\/[\w\+\.-]+)/, '')
var extensions = match[2]
.split(/\s+/)
.filter(Boolean)
var o = json[mime] = {}
Expand Down

0 comments on commit 7315783

Please sign in to comment.