FileType (file_type v0.1.0) View Source
Detect the MIME type of a file based on it's content.
Link to this section Summary
Link to this section Types
Specs
error() :: File.posix() | :unrecognized
Specs
ext() :: binary()
Specs
mime() :: binary()
Specs
Specs
Link to this section Functions
Specs
Format an error returned by this library.
Examples
iex> FileType.format_error(:unrecognized)
"does not match any known format"
iex> FileType.format_error(:enoent)
"no such file or directory"
Specs
Determines a MIME type from an IO device.
Examples
iex> {:ok, io} = File.open("profile.png", [:read, :binary])
{:ok, #PID<0.109.0>}
iex> FileType.from_io(io)
{:ok, {"png", "image/png"}}
Specs
This is the same as from_io/1
, except that it will open and close
a file for you.
Examples
iex> FileType.from_path("profile.png")
{:ok, {"png", "image/png"}}
iex> FileType.from_path("contract.docx")
{:ok, {"docx", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"}}
iex> FileType.from_path("example.txt")
{:error, :unrecognized}
iex> FileType.from_path("does-not-exist.png")
{:error, :enoent}