This repository has been archived by the owner. It is now read-only.

mime.cr

**Unmaintained** Mime types for Crystal.

Mime.cr

Language Tag Build Status License

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

  1. Fork it (https://github.com/icyleaf/mime/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • icyleaf icyleaf - creator, maintainer
Repository

mime.cr

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 0
  • about 6 years ago
  • June 25, 2018
License

MIT License

Links
Synced at

Sun, 17 Nov 2024 05:14:27 GMT

Languages