MIME Types v0.1.1 MIME
Utilities for working with common MIME types.
The MIME types registry can be extended in your application configuration as follows:
config :mime_types, custom: %{
"application/vnd.api+json" => ["json-api"]
}
After adding the configuration, the MIME module needs to be recompiled. If you are using mix, this can be accomplished with:
$ mix deps.clean mime_types --build
$ mix deps.get
Summary
Functions
Returns a list of all known extensions associated with MIME types
Returns the extensions associated with a given MIME type.
Examples
iex> MIME.extensions("text/html")
["html", "htm"]
iex> MIME.extensions("application/json")
["json"]
iex> MIME.extensions("foo/bar")
[]
Returns a Keyword list of MIME types and their associated extensions
Guesses the MIME type based on the path’s extension. See type/1
.
Examples
iex> MIME.path("index.html")
"text/html"
Returns the MIME type associated with a file extension. If no MIME type is
known for file_extension
, "application/octet-stream"
is returned.
Examples
iex> MIME.type("txt")
"text/plain"
iex> MIME.type("foobarbaz")
"application/octet-stream"
Returns a list of all known MIME types
Returns whether a MIME type is registered.
Examples
iex> MIME.valid?("text/plain")
true
iex> MIME.valid?("foo/bar")
false
Functions
Specs
extensions :: [String.t]
Returns a list of all known extensions associated with MIME types.
Returns the extensions associated with a given MIME type.
Examples
iex> MIME.extensions("text/html")
["html", "htm"]
iex> MIME.extensions("application/json")
["json"]
iex> MIME.extensions("foo/bar")
[]
Specs
mapping :: Keyword.t
Returns a Keyword list of MIME types and their associated extensions.
Guesses the MIME type based on the path’s extension. See type/1
.
Examples
iex> MIME.path("index.html")
"text/html"
Returns the MIME type associated with a file extension. If no MIME type is
known for file_extension
, "application/octet-stream"
is returned.
Examples
iex> MIME.type("txt")
"text/plain"
iex> MIME.type("foobarbaz")
"application/octet-stream"
Specs
valid?(String.t) :: boolean
Returns whether a MIME type is registered.
Examples
iex> MIME.valid?("text/plain")
true
iex> MIME.valid?("foo/bar")
false