Infer (Infer v0.2.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 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 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

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

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

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

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

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

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

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"}

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.png?/1, matcher_type: :image, mime_type: "image/png"}

Specs

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

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

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

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

Specs

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

Returns whether the given extension is supported.

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

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