mime~icyleaf
Mime.cr
Mime types for Crystal. Data from node-mime and inspired from mime-types.
Installation
Add this to your application's shard.yml
:
dependencies:
mime:
github: icyleaf/mime.cr
API
require "mime"
Mime.loopup(path)
Lookup the content-type associated with a file.
Mime.lookup "db.json" # => application/json
Mime.lookup ".md" # => text/markdown
Mime.lookup "xml" # => application/xml
Mime.lookup "path/to/file.js" # => application/javascript
Mime.lookup ".gitignore" # => nil
Mime.content_type(type)
Create a full content-type header given file(extension) or content-type
Mime.content_type "db.json" # => application/json, charset=utf-8
Mime.content_type "xml", "GBK2312" # => application/xml, charset=gbk2312
Mime.content_type ".gitignore" # => nil
Mime.extension(type)
Get the extension from a content-type.
Mime.extension "text/html" # => html
Mime.extension "i-dont-know" # => nil
Mime.charset(type)
Get the charset from a content-type.
Mime.charset "application/json; charset=gbk2312" # => gbk2312
Mime.charset "text/html" # => utf-8
Development
Update data to db file
$ shards build
$ ./bin/mime_builder
I, [2018-06-25 14:29:33 +08:00 #63109] INFO -- : Download standard mime types ...
I, [2018-06-25 14:29:36 +08:00 #63109] INFO -- : New mime types found: 2.
I, [2018-06-25 14:29:38 +08:00 #65239] INFO -- : Write to file ...
Contributing
- Fork it (https://github.com/icyleaf/mime/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- icyleaf icyleaf - creator, maintainer