tree_magic v0.1.0 TreeMagic
Binding to tree_magic, providing MIME information for files.
Link to this section Summary
Functions
Get the MIME type of a file, given its path.
Get the MIME type of a string.
Determines if a MIME is an alias of another MIME
Check if the given filepath matches the given MIME type.
Checks if the given string matches the given MIME type.
Link to this section Types
Link to this section Functions
from_filepath(path)
Get the MIME type of a file, given its path.
Will return an error if the file is missing.
iex> TreeMagic.from_filepath("test/fixtures/150.png")
iex> TreeMagic.from_filepath("test/fixtures/VeryImportant.odt")
iex> TreeMagic.from_filepath("missing.png")
Get the MIME type of a string.
iex> bytes = File.read!("test/fixtures/150.png") iex> TreeMagic.from_u8(bytes) "image/png" iex> bytes = File.read!("test/fixtures/VeryImportant.odt") iex> TreeMagic.from_u8(bytes) "application/vnd.oasis.opendocument.text"
Determines if a MIME is an alias of another MIME
If this returns true, that means the two MIME types are equivalent. If this returns false, either one of the MIME types are missing, or they are different.
iex> TreeMagic.is_alias("application/zip", "application/x-zip-compressed") true
match_filepath(mimetype, path)
Check if the given filepath matches the given MIME type.
If the given MIME type is not known or if the file could not be read, false will be returned.
iex> TreeMagic.match_filepath("image/png", "test/fixtures/150.png") true iex> TreeMagic.match_filepath("application/zip", "test/fixtures/150.png") false iex> TreeMagic.match_filepath("image/png", "missing.png") false
Checks if the given string matches the given MIME type.
Returns true or false if it matches or not. If the given MIME type is not known, the function will always return false. If mimetype is an alias of a known MIME, the file will be checked agains that MIME.
iex> bytes = File.read!("test/fixtures/150.png") iex> TreeMagic.match_u8("image/png", bytes) true iex> TreeMagic.match_u8("application/zip", bytes) false