View Source Infer (Infer v0.2.6)

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 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 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 and byte size as argument.

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 extension.

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

app?(binary()) :: boolean()

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

examples

Examples

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

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

Specs

archive?(binary()) :: boolean()

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

examples

Examples

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

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

Specs

audio?(binary()) :: boolean()

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

examples

Examples

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

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

Specs

book?(binary()) :: boolean()

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

examples

Examples

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

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

Specs

document?(binary()) :: boolean()

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

examples

Examples

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

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

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

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

Specs

font?(binary()) :: boolean()

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

examples

Examples

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

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

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

Examples

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

get_from_path(path, byte_size \\ 2048)

View Source

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

examples

Examples

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

iex> Infer.get_from_path("test/docs/sample.pptx")
%Infer.Type{extension: "pptx", matcher: &Infer.Doc.pptx?/1, matcher_type: :doc, mime_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation"}

iex> Infer.get_from_path("test/docs/unknown.path")
nil

Specs

image?(binary()) :: boolean()

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

examples

Examples

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

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

Specs

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

examples

Examples

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

mime?(binary, mime_type)

View Source

Specs

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

examples

Examples

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

mime_supported?(mime_type)

View Source

Specs

mime_supported?(Infer.Type.mime_type()) :: boolean()

Returns whether the given mime type is supported.

examples

Examples

iex> Infer.mime_supported?("image/png")
true

Specs

supported?(Infer.Type.extension()) :: boolean()

Returns whether the given extension is supported.

examples

Examples

iex> Infer.supported?("png")
true

Specs

video?(binary()) :: boolean()

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

examples

Examples

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

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