Infer (Infer v0.1.0) View Source

A dependency free library to infer file and MIME type by checking the magic number signature.

An elixir adaption of the infer rust library.

Link to this section Summary

Functions

Takes the binary file contents as argument and returns the Infer.Type.t/0 if the file matches one of the supported types. Returns nil otherwise.

Same as Infer.get/1, but takes the file path as argument.

Takes the binary content and the file extension as arguments. Returns whether the file content is of the given extension.

Takes the binary file contents as argument and returns whether the file is an application or not.

Takes the binary file contents as argument and returns whether the file is an archive or not.

Takes the binary file contents as argument and returns whether the file is an archive or not.

Takes the binary file contents as argument and returns whether the file is an book (epub or mobi) or not.

Takes the binary file contents as argument and returns whether the file is a document (microsoft office, open office)

Takes the binary file contents as argument and returns whether the file is a font or not.

Takes the binary file contents as argument and returns whether the file is an image or not.

Takes the binary content and the file extension as arguments. Returns whether the file content is of the given mime type.

Returns whether the given mime type is supported.

Returns whether the given extension is supported.

Takes the binary file contents as argument and returns whether the file is a video or not.

Link to this section Functions

Specs

get(binary()) :: Infer.Type.t() | nil

Takes the binary file contents as argument and returns the Infer.Type.t/0 if the file matches one of the supported types. Returns nil otherwise.

Examples

iex> binary = File.read!("test/images/sample.png")
iex> Infer.get(binary)
%Infer.Type{extension: "png", matcher: &Infer.Image.is_png/1, matcher_type: :image, mime_type: "image/png"}

Specs

get_from_path(binary()) :: Infer.Type.t() | nil

Same as Infer.get/1, but takes the file path as argument.

Examples

iex> Infer.get_from_path("test/images/sample.png")
%Infer.Type{extension: "png", matcher: &Infer.Image.is_png/1, matcher_type: :image, mime_type: "image/png"}

Specs

Takes the binary content and the file extension as arguments. Returns whether the file content is of the given extension.

Examples

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is(binary, "png")
true

Specs

is_app(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is an application or not.

Examples

iex> binary = File.read!("test/app/sample.wasm")
iex> Infer.is_app(binary)
true

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_app(binary)
false

Specs

is_archive(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is an archive or not.

Examples

iex> binary = File.read!("test/archives/sample.zip")
iex> Infer.is_archive(binary)
true

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_archive(binary)
false

Specs

is_audio(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is an archive or not.

Examples

iex> binary = File.read!("test/audio/sample.mp3")
iex> Infer.is_audio(binary)
true

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_audio(binary)
false

Specs

is_book(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is an book (epub or mobi) or not.

Examples

iex> binary = File.read!("test/books/sample.epub")
iex> Infer.is_book(binary)
true

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_book(binary)
false

Specs

is_document(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is a document (microsoft office, open office)

Examples

iex> binary = File.read!("test/docs/sample.xlsx")
iex> Infer.is_document(binary)
true

iex> binary = File.read!("test/docs/sample.pptx")
iex> Infer.is_document(binary)
true

iex> binary = File.read!("test/docs/sample.odp")
iex> Infer.is_document(binary)
true

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_document(binary)
false

Specs

is_font(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is a font or not.

Examples

iex> binary = File.read!("test/fonts/sample.ttf")
iex> Infer.is_font(binary)
true

iex> binary = File.read!("test/app/sample.wasm")
iex> Infer.is_font(binary)
false

Specs

is_image(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is an image or not.

Examples

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_image(binary)
true

iex> binary = File.read!("test/app/sample.wasm")
iex> Infer.is_image(binary)
false
Link to this function

is_mime(binary, mime_type)

View Source

Specs

is_mime(binary(), Infer.Type.mime_type()) :: boolean()

Takes the binary content and the file extension as arguments. Returns whether the file content is of the given mime type.

Examples

iex> binary = File.read!("test/images/sample.png")
iex> Infer.is_mime(binary, "image/png")
true
Link to this function

is_mime_supported(mime_type)

View Source

Specs

is_mime_supported(Infer.Type.mime_type()) :: boolean()

Returns whether the given mime type is supported.

Examples

iex> Infer.is_mime_supported("image/png")
true

Specs

is_supported(Infer.Type.extension()) :: boolean()

Returns whether the given extension is supported.

Examples

iex> Infer.is_supported("png")
true

Specs

is_video(binary()) :: boolean()

Takes the binary file contents as argument and returns whether the file is a video or not.

Examples

iex> binary = File.read!("test/videos/sample.mp4")
iex> Infer.is_video(binary)
true

iex> binary = File.read!("test/app/sample.wasm")
iex> Infer.is_video(binary)
false