Plug.MIME

Maps MIME types to file extensions and vice versa.

Source

Summary

extensions(type)

Returns the extensions associated with a given MIME type

path(path)

Guesses the MIME type based on the path’s extension. See type/1

type(file_extension)

Returns the MIME type associated with a file extension. If no MIME type is known for file_extension, \"application/octet-stream\" is returned

valid?(type)

Returns whether a MIME type is registered

Functions

extensions(type)

Specs:

Returns the extensions associated with a given MIME type.

Examples

iex\> Plug.MIME.extensions(\"text/html\")
[\"html\", \"htm\"]

iex\> Plug.MIME.extensions(\"application/json\")
[\"json\"]

iex\> Plug.MIME.extensions(\"foo/bar\")
[]
Source
path(path)

Specs:

Guesses the MIME type based on the path’s extension. See type/1.

Examples

iex\> Plug.MIME.path(\"index.html\")
\"text/html\"
Source
type(file_extension)

Specs:

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\> Plug.MIME.type(\"txt\")
\"text/plain\"

iex\> Plug.MIME.type(\"foobarbaz\")
\"application/octet-stream\"
Source
valid?(type)

Specs:

Returns whether a MIME type is registered.

Examples

iex\> Plug.MIME.valid?(\"text/plain\")
true

iex\> Plug.MIME.valid?(\"foo/bar\")
false
Source