Skip to content

MIME information: filetype, encoding, gzip

License

Notifications You must be signed in to change notification settings

JuliaWeb/MIMEs.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MIMEs.jl

A small package to transform between file extensions and MIME types, with bonus features.

Examples

julia> using MIMEs

### For filename extensions:
julia> m = mime_from_extension(".json")
MIME type application/json

julia> extension_from_mime(m)
".json"


### For web servers:
julia> compressible_from_mime(m) # whether content of this MIME can/should be gzipped
true

julia> charset_from_mime(m)
"UTF-8"

julia> contenttype_from_mime(m) # the Content-Type HTTP header
"application/json; charset=utf-8"

julia> mime_from_contenttype("application/json; charset=utf-8")
MIME type application/json

Implementation

This package uses the popular jshttp/mime-db database. This database is an aggregation of the following sources:

The function implementations, including resolution for conflicting extensions (nginx > apache > mime-db > IANA), is based on jshttp/mime-types.

Performance

The database is parsed and processed by us, and written directly to the source code (see #3). This means that the package has no dependencies, and loads very fast:

julia> @time import MIMEs; MIMEs.mime_from_path("a/foo.txt")
  0.023083 seconds (36.38 k allocations: 3.107 MiB, 39.83% compilation time)

Opinions

While mostly cold and technical, this package contains a couple of opinionated choices:

  • We use multiple sources for MIME information, and when these sources have conflicting/duplicate information, we
  • text/javascript is used for .js and .mjs files, not application/javascript. This transition is still underway in official channels, but @fonsp prefers to start using text/javascript today. More info →
  • text/julia is used for .jl files. This MIME is not (yet) official: More info →

See also

  • tkf/MIMEFileExtensions.jl: Similar smaller package based on the Apache database, for MIME <-> extension conversion only. MIMEs.jl also contains additional MIME-related queries useful for writing servers.
  • JuliaIO/FileType.jl: File type (including MIME) detection based also on the file content.

Future development & scope

Future goals of MIMEs.jl:

  • All things MIME! If you are writing a web application in Julia and you are missing MIME-related functionality, let us know! Issues and Pull Requests are welcome.
  • This package will be regularly updated to match the (monthly) updates to jshttp/mime-db. Right now this is involves manually running the update script, but we might automate this in the future. More info →