-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f49524d
Showing
5 changed files
with
455 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright (c) 2011 Matthew "LeafStorm" Frazier | ||
|
||
Permission is hereby granted, free of charge, to any person | ||
obtaining a copy of this software and associated documentation | ||
files (the "Software"), to deal in the Software without | ||
restriction, including without limitation the rights to use, | ||
copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following | ||
conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
====== | ||
|
||
In addition, the MIME types contained in the Software were | ||
originally obtained from the Python 2.7.1 ``mimetypes.py`` module, | ||
though they have been considerably modified and augmented. | ||
Said file was made available under the Python Software Foundation | ||
license (http://python.org/psf/license/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
mimetypes.lua | ||
Version 1.0.0 | ||
|
||
This is just a quick Lua library designed to provide a nice, non-server-bound | ||
database of MIME types. Usage is simple: | ||
|
||
local mimetypes = require 'mimetypes' | ||
mimetypes.guess "docs.txt" -- text/plain | ||
mimetypes.guess "word.doc" -- application/msword | ||
mimetypes.guess "init.lua" -- text/x-lua | ||
|
||
Should you need your own MIME types, you can do this: | ||
|
||
local mimedb = mimetypes.copy() | ||
mimedb.extensions["ext"] = "application/x-cool-type" | ||
mimetypes.guess("myfile.ext", mimedb) -- application/x-cool-type | ||
|
||
If you want to make sure it works, run `lua test.lua` (or use Shake). | ||
|
||
|
||
## API | ||
|
||
`mimetypes.copy([db])` - Copies the default MIME types database and returns | ||
the copy. If you provide `db`, it is copied instead of the default. | ||
|
||
`mimetypes.guess(filename[, db])` - Guesses the MIME type of the file named | ||
`filename`. If a MIME type could not be ascertained, nil is returned. If you | ||
provide `db`, it is used to look up the MIME type instead of the default | ||
database. | ||
|
||
|
||
## Databases | ||
|
||
Each database is a table that contains two fields - `extensions` and | ||
`filenames`. `filenames` is checked first, as it maps literal filenames | ||
(like `README`) to MIME types. | ||
|
||
If that doesn't work, the file's extension is taken and looked up in | ||
`extensions`. (For example, `report.pdf` would look up `pdf` and return the | ||
MIME type there, which is `application/pdf`.) | ||
|
||
The default database is immutable (and hidden), because it's shared between | ||
everyone who calls `guess` without arguments, and messing with it would be a | ||
bad thing. | ||
|
||
|
||
## Bugs | ||
|
||
If you encounter any missing, inaccurate, or questionably assigned MIME types, | ||
file a bug (preferably including a diff) on the issue tracker at | ||
<http://www.bitbucket.org/leafstorm/lua-mimetypes/>, or e-mail me at | ||
<leafstormrush@gmail.com>. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# This Python script was used to generate most of the MIME types. | ||
# The original run was on Python 2.7.1. | ||
|
||
import mimetypes | ||
from operator import itemgetter | ||
|
||
list = mimetypes.types_map.items() | ||
|
||
def sortkey(pair): | ||
return pair[1].split("/")[0], pair[0] | ||
|
||
list.sort(key=sortkey) | ||
|
||
for (ext, mt) in list: | ||
print ('extensions[%r] = %r' % (ext.lstrip("."), mt)) |
Oops, something went wrong.