MIME type utility module.
luarocks install mediatypes
Parameters
mimetypes:string: mime types definition string. (default:mediatype.default)
Returns
mt:table: mediatypes object
Example
local MediaTypes = require('mediatypes');
local mt = MediaTypes.new([[
my/mimetype my myfile; # this is my example mime type definition
]]);add new mime types from a mime types definition string.
Parameters
mimetypes:string: mime string.
Example
mt:read([[
# JavaScript
application/javascript js;
application/json json;
]]);returns a MIME type string associated with ext argument.
Parameters
ext:string: extension string.
Returns
mime:string: mime type string or nil.
Example
print( mt:getmime('my') ); -- 'my/mimetype'
print( mt:getmime('myfile') ); -- 'my/mimetype'returns a extension strings table associated with mime argument.
Parameters
mime:string: mime string.
Returns
exts:table: extension strings table or nil.
Example
--[[ output
1 my
2 myfile
--]]
for i, ext in ipairs( mt:getExt('my/mimetype') ) do
print( i, ext );
end