diff --git a/CHANGELOG.md b/CHANGELOG.md index ded968c..462445b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.2.0 (2022-01-09) + +* Changes + * `is_*` functions have no prefix and end with a question mark, to conform with elixir's conventions + ## 0.1.1 (2022-01-09) * Enhancements diff --git a/README.md b/README.md index ffba8f9..9ea6119 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ by adding `infer` to your list of dependencies in `mix.exs`: ```elixir def deps do [ - {:infer, "~> 0.1.1"} + {:infer, "~> 0.2.0"} ] end ``` @@ -29,7 +29,7 @@ Takes the binary file contents as argument and returns the `Infer.Type.t()` if t ```elixir 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"} +%Infer.Type{extension: "png", matcher: &Infer.Image.png?/1, matcher_type: :image, mime_type: "image/png"} ``` ### `Infer.get_from_path/1` @@ -38,58 +38,58 @@ Similar to `Infer.get/1`, but takes the file path as argument. ```elixir 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"} +%Infer.Type{extension: "png", matcher: &Infer.Image.png?/1, matcher_type: :image, mime_type: "image/png"} ``` -### `Infer.is/2` +### `Infer.is?/2` Takes the binary content and the file extension as arguments. Returns whether the file content is of the given extension. ```elixir iex> binary = File.read!("test/images/sample.png") -iex> Infer.is(binary, "png") +iex> Infer.is?(binary, "png") true ``` -### `Infer.is_mime/2` +### `Infer.mime?/2` Takes the binary content and the file extension as arguments. Returns whether the file content is of the given mime type. ```elixir iex> binary = File.read!("test/images/sample.png") -iex> Infer.is_mime(binary, "image/png") +iex> Infer.mime?(binary, "image/png") true ``` -### `Infer.is_image/1` +### `Infer.image?/1` Takes the binary file contents as argument and returns whether the file is an image or not. ```elixir iex> binary = File.read!("test/images/sample.png") -iex> Infer.is_image(binary) +iex> Infer.image?(binary) true ``` -### `Infer.is_document/1` +### `Infer.document?/1` Takes the binary file contents as argument and returns whether the file is a document (microsoft office, open office) ```elixir iex> binary = File.read!("test/docs/sample.xlsx") -iex> Infer.is_document(binary) +iex> Infer.document?(binary) true ``` -### `Infer.Doc.is_docx/1` +### `Infer.Doc.docx?/1` Takes the binary file contents as arguments. Returns `true` if it's Microsoft Word Open XML Format Document (DOCX) data. ```elixir iex> binary = File.read!("test/docs/sample.docx") -iex> Infer.Doc.is_docx(binary) +iex> Infer.Doc.docx?(binary) true ``` diff --git a/lib/infer.ex b/lib/infer.ex index 2a2116d..fd104ce 100644 --- a/lib/infer.ex +++ b/lib/infer.ex @@ -25,7 +25,7 @@ defmodule Infer do 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"} + %Infer.Type{extension: "png", matcher: &Infer.Image.png?/1, matcher_type: :image, mime_type: "image/png"} """ @spec get(binary()) :: Infer.Type.t() | nil @@ -37,7 +37,7 @@ defmodule Infer do ## 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"} + %Infer.Type{extension: "png", matcher: &Infer.Image.png?/1, matcher_type: :image, mime_type: "image/png"} """ @spec get_from_path(binary()) :: Infer.Type.t() | nil @@ -53,12 +53,12 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/images/sample.png") - iex> Infer.is(binary, "png") + iex> Infer.is?(binary, "png") true """ - @spec is(binary(), Infer.Type.extension()) :: boolean() - def is(binary, extension), do: Enum.any?(@matchers, &(&1.extension == extension && &1.matcher.(binary))) + @spec is?(binary(), Infer.Type.extension()) :: boolean() + def is?(binary, extension), do: Enum.any?(@matchers, &(&1.extension == extension && &1.matcher.(binary))) @doc """ Takes the binary content and the file extension as arguments. Returns whether the file content is @@ -67,36 +67,36 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_mime(binary, "image/png") + iex> Infer.mime?(binary, "image/png") true """ - @spec is_mime(binary(), Infer.Type.mime_type()) :: boolean() - def is_mime(binary, mime_type), do: Enum.any?(@matchers, &(&1.mime_type == mime_type && &1.matcher.(binary))) + @spec mime?(binary(), Infer.Type.mime_type()) :: boolean() + def mime?(binary, mime_type), do: Enum.any?(@matchers, &(&1.mime_type == mime_type && &1.matcher.(binary))) @doc """ Returns whether the given extension is supported. ## Examples - iex> Infer.is_supported("png") + iex> Infer.supported?("png") true """ - @spec is_supported(Infer.Type.extension()) :: boolean() - def is_supported(extension), do: Enum.any?(@matchers, &(&1.extension == extension)) + @spec supported?(Infer.Type.extension()) :: boolean() + def supported?(extension), do: Enum.any?(@matchers, &(&1.extension == extension)) @doc """ Returns whether the given mime type is supported. ## Examples - iex> Infer.is_mime_supported("image/png") + iex> Infer.mime_supported?("image/png") true """ - @spec is_mime_supported(Infer.Type.mime_type()) :: boolean() - def is_mime_supported(mime_type), do: Enum.any?(@matchers, &(&1.mime_type == mime_type)) + @spec mime_supported?(Infer.Type.mime_type()) :: boolean() + def mime_supported?(mime_type), do: Enum.any?(@matchers, &(&1.mime_type == mime_type)) @doc """ Takes the binary file contents as argument and returns whether the file is an application or not. @@ -104,16 +104,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.is_app(binary) + iex> Infer.app?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_app(binary) + iex> Infer.app?(binary) false """ - @spec is_app(binary()) :: boolean() - def is_app(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :app && &1.matcher.(binary))) + @spec app?(binary()) :: boolean() + def app?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :app && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is an archive or not. @@ -121,16 +121,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/archives/sample.zip") - iex> Infer.is_archive(binary) + iex> Infer.archive?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_archive(binary) + iex> Infer.archive?(binary) false """ - @spec is_archive(binary()) :: boolean() - def is_archive(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :archive && &1.matcher.(binary))) + @spec archive?(binary()) :: boolean() + def archive?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :archive && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is an archive or not. @@ -138,16 +138,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/audio/sample.mp3") - iex> Infer.is_audio(binary) + iex> Infer.audio?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_audio(binary) + iex> Infer.audio?(binary) false """ - @spec is_audio(binary()) :: boolean() - def is_audio(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :audio && &1.matcher.(binary))) + @spec audio?(binary()) :: boolean() + def audio?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :audio && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is an book (epub or mobi) or not. @@ -155,16 +155,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/books/sample.epub") - iex> Infer.is_book(binary) + iex> Infer.book?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_book(binary) + iex> Infer.book?(binary) false """ - @spec is_book(binary()) :: boolean() - def is_book(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :book && &1.matcher.(binary))) + @spec book?(binary()) :: boolean() + def book?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :book && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is a document (microsoft office, open office) @@ -172,24 +172,24 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/docs/sample.xlsx") - iex> Infer.is_document(binary) + iex> Infer.document?(binary) true iex> binary = File.read!("test/docs/sample.pptx") - iex> Infer.is_document(binary) + iex> Infer.document?(binary) true iex> binary = File.read!("test/docs/sample.odp") - iex> Infer.is_document(binary) + iex> Infer.document?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_document(binary) + iex> Infer.document?(binary) false """ - @spec is_document(binary()) :: boolean() - def is_document(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :doc && &1.matcher.(binary))) + @spec document?(binary()) :: boolean() + def document?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :doc && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is a font or not. @@ -197,16 +197,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/fonts/sample.ttf") - iex> Infer.is_font(binary) + iex> Infer.font?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.is_font(binary) + iex> Infer.font?(binary) false """ - @spec is_font(binary()) :: boolean() - def is_font(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :font && &1.matcher.(binary))) + @spec font?(binary()) :: boolean() + def font?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :font && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is an image or not. @@ -214,16 +214,16 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/images/sample.png") - iex> Infer.is_image(binary) + iex> Infer.image?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.is_image(binary) + iex> Infer.image?(binary) false """ - @spec is_image(binary()) :: boolean() - def is_image(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :image && &1.matcher.(binary))) + @spec image?(binary()) :: boolean() + def image?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :image && &1.matcher.(binary))) @doc """ Takes the binary file contents as argument and returns whether the file is a video or not. @@ -231,14 +231,14 @@ defmodule Infer do ## Examples iex> binary = File.read!("test/videos/sample.mp4") - iex> Infer.is_video(binary) + iex> Infer.video?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.is_video(binary) + iex> Infer.video?(binary) false """ - @spec is_video(binary()) :: boolean() - def is_video(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :video && &1.matcher.(binary))) + @spec video?(binary()) :: boolean() + def video?(binary), do: Enum.any?(@matchers, &(&1.matcher_type == :video && &1.matcher.(binary))) end diff --git a/lib/matchers.ex b/lib/matchers.ex index 0ca684c..1955763 100644 --- a/lib/matchers.ex +++ b/lib/matchers.ex @@ -6,149 +6,149 @@ defmodule Infer.Matchers do def list do [ # App - %Infer.Type{matcher_type: :app, mime_type: "application/wasm", extension: "wasm", matcher: &Infer.App.is_wasm/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/x-executable", extension: "elf", matcher: &Infer.App.is_elf/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/wasm", extension: "wasm", matcher: &Infer.App.wasm?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/x-executable", extension: "elf", matcher: &Infer.App.elf?/1}, %Infer.Type{ matcher_type: :app, mime_type: "application/vnd.microsoft.portable-executable", extension: "exe", - matcher: &Infer.App.is_exe/1 + matcher: &Infer.App.exe?/1 }, %Infer.Type{ matcher_type: :app, mime_type: "application/vnd.microsoft.portable-executable", extension: "dll", - matcher: &Infer.App.is_dll/1 + matcher: &Infer.App.dll?/1 }, - %Infer.Type{matcher_type: :app, mime_type: "application/java", extension: "class", matcher: &Infer.App.is_java/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/x-llvm", extension: "bc", matcher: &Infer.App.is_llvm/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/x-mach-binary", extension: "mach", matcher: &Infer.App.is_mach/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/vnd.android.dex", extension: "dex", matcher: &Infer.App.is_dex/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/vnd.android.dey", extension: "dey", matcher: &Infer.App.is_dey/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/x-x509-ca-cert", extension: "der", matcher: &Infer.App.is_der/1}, - %Infer.Type{matcher_type: :app, mime_type: "application/x-executable", extension: "obj", matcher: &Infer.App.is_coff/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/java", extension: "class", matcher: &Infer.App.java?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/x-llvm", extension: "bc", matcher: &Infer.App.llvm?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/x-mach-binary", extension: "mach", matcher: &Infer.App.mach?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/vnd.android.dex", extension: "dex", matcher: &Infer.App.dex?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/vnd.android.dey", extension: "dey", matcher: &Infer.App.dey?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/x-x509-ca-cert", extension: "der", matcher: &Infer.App.der?/1}, + %Infer.Type{matcher_type: :app, mime_type: "application/x-executable", extension: "obj", matcher: &Infer.App.coff?/1}, # Book - %Infer.Type{matcher_type: :book, mime_type: "application/epub+zip", extension: "epub", matcher: &Infer.Book.is_epub/1}, - %Infer.Type{matcher_type: :book, mime_type: "application/x-mobipocket-ebook", extension: "mobi", matcher: &Infer.Book.is_mobi/1}, + %Infer.Type{matcher_type: :book, mime_type: "application/epub+zip", extension: "epub", matcher: &Infer.Book.epub?/1}, + %Infer.Type{matcher_type: :book, mime_type: "application/x-mobipocket-ebook", extension: "mobi", matcher: &Infer.Book.mobi?/1}, # Image - %Infer.Type{matcher_type: :image, mime_type: "image/jpeg", extension: "jpg", matcher: &Infer.Image.is_jpeg/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/jp2", extension: "jp2", matcher: &Infer.Image.is_jpeg2000/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/png", extension: "png", matcher: &Infer.Image.is_png/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/gif", extension: "gif", matcher: &Infer.Image.is_gif/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/webp", extension: "webp", matcher: &Infer.Image.is_webp/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/x-canon-cr2", extension: "cr2", matcher: &Infer.Image.is_cr2/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/tiff", extension: "tif", matcher: &Infer.Image.is_tiff/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/bmp", extension: "bmp", matcher: &Infer.Image.is_bmp/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/vnd.ms-photo", extension: "jxr", matcher: &Infer.Image.is_jxr/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/vnd.adobe.photoshop", extension: "psd", matcher: &Infer.Image.is_psd/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/vnd.microsoft.icon", extension: "ico", matcher: &Infer.Image.is_ico/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/heif", extension: "heif", matcher: &Infer.Image.is_heif/1}, - %Infer.Type{matcher_type: :image, mime_type: "image/avif", extension: "avif", matcher: &Infer.Image.is_avif/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/jpeg", extension: "jpg", matcher: &Infer.Image.jpeg?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/jp2", extension: "jp2", matcher: &Infer.Image.jpeg2000?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/png", extension: "png", matcher: &Infer.Image.png?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/gif", extension: "gif", matcher: &Infer.Image.gif?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/webp", extension: "webp", matcher: &Infer.Image.webp?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/x-canon-cr2", extension: "cr2", matcher: &Infer.Image.cr2?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/tiff", extension: "tif", matcher: &Infer.Image.tiff?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/bmp", extension: "bmp", matcher: &Infer.Image.bmp?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/vnd.ms-photo", extension: "jxr", matcher: &Infer.Image.jxr?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/vnd.adobe.photoshop", extension: "psd", matcher: &Infer.Image.psd?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/vnd.microsoft.icon", extension: "ico", matcher: &Infer.Image.ico?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/heif", extension: "heif", matcher: &Infer.Image.heif?/1}, + %Infer.Type{matcher_type: :image, mime_type: "image/avif", extension: "avif", matcher: &Infer.Image.avif?/1}, # Video - %Infer.Type{matcher_type: :video, mime_type: "video/mp4", extension: "mp4", matcher: &Infer.Video.is_mp4/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/x-m4v", extension: "m4v", matcher: &Infer.Video.is_m4v/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/x-matroska", extension: "mkv", matcher: &Infer.Video.is_mkv/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/webm", extension: "webm", matcher: &Infer.Video.is_webm/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/quicktime", extension: "mov", matcher: &Infer.Video.is_mov/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/x-msvideo", extension: "avi", matcher: &Infer.Video.is_avi/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/x-ms-wmv", extension: "wmv", matcher: &Infer.Video.is_wmv/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/mpeg", extension: "mpg", matcher: &Infer.Video.is_mpeg/1}, - %Infer.Type{matcher_type: :video, mime_type: "video/x-flv", extension: "flv", matcher: &Infer.Video.is_flv/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/mp4", extension: "mp4", matcher: &Infer.Video.mp4?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/x-m4v", extension: "m4v", matcher: &Infer.Video.m4v?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/x-matroska", extension: "mkv", matcher: &Infer.Video.mkv?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/webm", extension: "webm", matcher: &Infer.Video.webm?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/quicktime", extension: "mov", matcher: &Infer.Video.mov?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/x-msvideo", extension: "avi", matcher: &Infer.Video.avi?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/x-ms-wmv", extension: "wmv", matcher: &Infer.Video.wmv?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/mpeg", extension: "mpg", matcher: &Infer.Video.mpeg?/1}, + %Infer.Type{matcher_type: :video, mime_type: "video/x-flv", extension: "flv", matcher: &Infer.Video.flv?/1}, # Audio - %Infer.Type{matcher_type: :audio, mime_type: "audio/midi", extension: "midi", matcher: &Infer.Audio.is_midi/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/mpeg", extension: "mp3", matcher: &Infer.Audio.is_mp3/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/m4a", extension: "m4a", matcher: &Infer.Audio.is_m4a/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/ogg", extension: "ogg", matcher: &Infer.Audio.is_ogg/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/x-flac", extension: "flac", matcher: &Infer.Audio.is_flac/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/x-wav", extension: "wav", matcher: &Infer.Audio.is_wav/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/amr", extension: "amr", matcher: &Infer.Audio.is_amr/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/aac", extension: "aac", matcher: &Infer.Audio.is_aac/1}, - %Infer.Type{matcher_type: :audio, mime_type: "audio/x-aiff", extension: "aiff", matcher: &Infer.Audio.is_aiff/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/midi", extension: "midi", matcher: &Infer.Audio.midi?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/mpeg", extension: "mp3", matcher: &Infer.Audio.mp3?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/m4a", extension: "m4a", matcher: &Infer.Audio.m4a?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/ogg", extension: "ogg", matcher: &Infer.Audio.ogg?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/x-flac", extension: "flac", matcher: &Infer.Audio.flac?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/x-wav", extension: "wav", matcher: &Infer.Audio.wav?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/amr", extension: "amr", matcher: &Infer.Audio.amr?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/aac", extension: "aac", matcher: &Infer.Audio.aac?/1}, + %Infer.Type{matcher_type: :audio, mime_type: "audio/x-aiff", extension: "aiff", matcher: &Infer.Audio.aiff?/1}, # Font - %Infer.Type{matcher_type: :font, mime_type: "application/font-woff", extension: "woff", matcher: &Infer.Font.is_woff/1}, - %Infer.Type{matcher_type: :font, mime_type: "application/font-woff2", extension: "woff2", matcher: &Infer.Font.is_woff2/1}, - %Infer.Type{matcher_type: :font, mime_type: "application/font-sfnt", extension: "ttf", matcher: &Infer.Font.is_ttf/1}, - %Infer.Type{matcher_type: :font, mime_type: "application/font-sfnt", extension: "otf", matcher: &Infer.Font.is_otf/1}, + %Infer.Type{matcher_type: :font, mime_type: "application/font-woff", extension: "woff", matcher: &Infer.Font.woff?/1}, + %Infer.Type{matcher_type: :font, mime_type: "application/font-woff2", extension: "woff2", matcher: &Infer.Font.woff2?/1}, + %Infer.Type{matcher_type: :font, mime_type: "application/font-sfnt", extension: "ttf", matcher: &Infer.Font.ttf?/1}, + %Infer.Type{matcher_type: :font, mime_type: "application/font-sfnt", extension: "otf", matcher: &Infer.Font.otf?/1}, # Doc - %Infer.Type{matcher_type: :doc, mime_type: "application/msword", extension: "doc", matcher: &Infer.Doc.is_doc/1}, + %Infer.Type{matcher_type: :doc, mime_type: "application/msword", extension: "doc", matcher: &Infer.Doc.doc?/1}, %Infer.Type{ matcher_type: :doc, mime_type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", extension: "docxc", - matcher: &Infer.Doc.is_docx/1 + matcher: &Infer.Doc.docx?/1 }, - %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.ms-excel", extension: "xls", matcher: &Infer.Doc.is_xls/1}, + %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.ms-excel", extension: "xls", matcher: &Infer.Doc.xls?/1}, %Infer.Type{ matcher_type: :doc, mime_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", extension: "xlsx", - matcher: &Infer.Doc.is_xlsx/1 + matcher: &Infer.Doc.xlsx?/1 }, - %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.ms-powerpoint", extension: "ppt", matcher: &Infer.Doc.is_ppt/1}, + %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.ms-powerpoint", extension: "ppt", matcher: &Infer.Doc.ppt?/1}, %Infer.Type{ matcher_type: :doc, mime_type: "application/vnd.openxmlformats-officedocument.presentationml.presentation", extension: "pptx", - matcher: &Infer.Doc.is_pptx/1 + matcher: &Infer.Doc.pptx?/1 }, - %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.oasis.opendocument.text", extension: "odt", matcher: &Infer.Doc.is_odt/1}, + %Infer.Type{matcher_type: :doc, mime_type: "application/vnd.oasis.opendocument.text", extension: "odt", matcher: &Infer.Doc.odt?/1}, %Infer.Type{ matcher_type: :doc, mime_type: "application/vnd.oasis.opendocument.spreadsheet", extension: "ods", - matcher: &Infer.Doc.is_ods/1 + matcher: &Infer.Doc.ods?/1 }, %Infer.Type{ matcher_type: :doc, mime_type: "application/vnd.oasis.opendocument.presentation", extension: "odp", - matcher: &Infer.Doc.is_odp/1 + matcher: &Infer.Doc.odp?/1 }, # Archive - %Infer.Type{matcher_type: :archive, mime_type: "application/epub+zip", extension: "epub", matcher: &Infer.Archive.is_epub/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/zip", extension: "zip", matcher: &Infer.Archive.is_zip/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-tar", extension: "tar", matcher: &Infer.Archive.is_tar/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/vnd.rar", extension: "rar", matcher: &Infer.Archive.is_rar/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/gzip", extension: "gz", matcher: &Infer.Archive.is_gz/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-bzip2", extension: "bz2", matcher: &Infer.Archive.is_bz2/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-7z-compressed", extension: "7z", matcher: &Infer.Archive.is_7z/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-xz", extension: "xz", matcher: &Infer.Archive.is_xz/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/pdf", extension: "pdf", matcher: &Infer.Archive.is_pdf/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-shockwave-flash", extension: "swf", matcher: &Infer.Archive.is_swf/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/rtf", extension: "rtf", matcher: &Infer.Archive.is_rtf/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/octet-stream", extension: "eot", matcher: &Infer.Archive.is_eot/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/postscript", extension: "ps", matcher: &Infer.Archive.is_ps/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/vnd.sqlite3", extension: "sqlite", matcher: &Infer.Archive.is_sqlite/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-nintendo-nes-rom", extension: "nes", matcher: &Infer.Archive.is_nes/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/epub+zip", extension: "epub", matcher: &Infer.Archive.epub?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/zip", extension: "zip", matcher: &Infer.Archive.zip?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-tar", extension: "tar", matcher: &Infer.Archive.tar?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/vnd.rar", extension: "rar", matcher: &Infer.Archive.rar?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/gzip", extension: "gz", matcher: &Infer.Archive.gz?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-bzip2", extension: "bz2", matcher: &Infer.Archive.bz2?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-7z-compressed", extension: "7z", matcher: &Infer.Archive.sevenz?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-xz", extension: "xz", matcher: &Infer.Archive.xz?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/pdf", extension: "pdf", matcher: &Infer.Archive.pdf?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-shockwave-flash", extension: "swf", matcher: &Infer.Archive.swf?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/rtf", extension: "rtf", matcher: &Infer.Archive.rtf?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/octet-stream", extension: "eot", matcher: &Infer.Archive.eot?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/postscript", extension: "ps", matcher: &Infer.Archive.ps?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/vnd.sqlite3", extension: "sqlite", matcher: &Infer.Archive.sqlite?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-nintendo-nes-rom", extension: "nes", matcher: &Infer.Archive.nes?/1}, %Infer.Type{ matcher_type: :archive, mime_type: "application/x-google-chrome-extension", extension: "crx", - matcher: &Infer.Archive.is_crx/1 + matcher: &Infer.Archive.crx?/1 }, %Infer.Type{ matcher_type: :archive, mime_type: "application/vnd.ms-cab-compressed", extension: "cab", - matcher: &Infer.Archive.is_cab/1 + matcher: &Infer.Archive.cab?/1 }, %Infer.Type{ matcher_type: :archive, mime_type: "application/vnd.debian.binary-package", extension: "deb", - matcher: &Infer.Archive.is_deb/1 + matcher: &Infer.Archive.deb?/1 }, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-unix-archive", extension: "ar", matcher: &Infer.Archive.is_ar/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-compressed", extension: "Z", matcher: &Infer.Archive.is_z/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-lzip", extension: "lz", matcher: &Infer.Archive.is_lz/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-rpm", extension: "rpm", matcher: &Infer.Archive.is_rpm/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/dicom", extension: "dcm", matcher: &Infer.Archive.is_dcm/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/zstd", extension: "zst", matcher: &Infer.Archive.is_zst/1}, - %Infer.Type{matcher_type: :archive, mime_type: "application/x-ole-storage", extension: "msi", matcher: &Infer.Archive.is_msi/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-unix-archive", extension: "ar", matcher: &Infer.Archive.ar?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-compressed", extension: "Z", matcher: &Infer.Archive.z?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-lzip", extension: "lz", matcher: &Infer.Archive.lz?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-rpm", extension: "rpm", matcher: &Infer.Archive.rpm?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/dicom", extension: "dcm", matcher: &Infer.Archive.dcm?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/zstd", extension: "zst", matcher: &Infer.Archive.zst?/1}, + %Infer.Type{matcher_type: :archive, mime_type: "application/x-ole-storage", extension: "msi", matcher: &Infer.Archive.msi?/1}, # Text - %Infer.Type{matcher_type: :text, mime_type: "text/html", extension: "html", matcher: &Infer.Text.is_html/1}, - %Infer.Type{matcher_type: :text, mime_type: "text/xml", extension: "xml", matcher: &Infer.Text.is_xml/1}, - %Infer.Type{matcher_type: :text, mime_type: "text/x-shellscript", extension: "sh", matcher: &Infer.Text.is_shell_script/1} + %Infer.Type{matcher_type: :text, mime_type: "text/html", extension: "html", matcher: &Infer.Text.html?/1}, + %Infer.Type{matcher_type: :text, mime_type: "text/xml", extension: "xml", matcher: &Infer.Text.xml?/1}, + %Infer.Type{matcher_type: :text, mime_type: "text/x-shellscript", extension: "sh", matcher: &Infer.Text.shell_script?/1} ] end end diff --git a/lib/matchers/app.ex b/lib/matchers/app.ex index 49af08a..e73e7d1 100644 --- a/lib/matchers/app.ex +++ b/lib/matchers/app.ex @@ -11,17 +11,17 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_wasm(binary) + iex> Infer.App.wasm?(binary) true iex> binary = File.read!("test/app/sample.exe") - iex> Infer.App.is_wasm(binary) + iex> Infer.App.wasm?(binary) false """ - @spec is_wasm(binary()) :: boolean() - def is_wasm(<<0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, _rest::binary>>), do: true - def is_wasm(_binary), do: false + @spec wasm?(binary()) :: boolean() + def wasm?(<<0x00, 0x61, 0x73, 0x6D, 0x01, 0x00, 0x00, 0x00, _rest::binary>>), do: true + def wasm?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a EXE or DLL. @@ -31,17 +31,17 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample.exe") - iex> Infer.App.is_exe(binary) + iex> Infer.App.exe?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_exe(binary) + iex> Infer.App.exe?(binary) false """ - @spec is_exe(binary()) :: boolean() - def is_exe(<<0x4D, 0x5A, _rest::binary>>), do: true - def is_exe(_binary), do: false + @spec exe?(binary()) :: boolean() + def exe?(<<0x4D, 0x5A, _rest::binary>>), do: true + def exe?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a EXE or DLL. @@ -51,17 +51,17 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample.exe") - iex> Infer.App.is_dll(binary) + iex> Infer.App.dll?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_dll(binary) + iex> Infer.App.dll?(binary) false """ - @spec is_dll(binary()) :: boolean() - def is_dll(<<0x4D, 0x5A, _rest::binary>>), do: true - def is_dll(_binary), do: false + @spec dll?(binary()) :: boolean() + def dll?(<<0x4D, 0x5A, _rest::binary>>), do: true + def dll?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a elf. @@ -71,32 +71,32 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample_elf") - iex> Infer.App.is_elf(binary) + iex> Infer.App.elf?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_elf(binary) + iex> Infer.App.elf?(binary) false """ - @spec is_elf(binary()) :: boolean() - def is_elf(<<0x7F, 0x45, 0x4C, 0x46, _rest::binary>> = binary) when byte_size(binary) > 52, do: true - def is_elf(_binary), do: false + @spec elf?(binary()) :: boolean() + def elf?(<<0x7F, 0x45, 0x4C, 0x46, _rest::binary>> = binary) when byte_size(binary) > 52, do: true + def elf?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's compiled java bytecode. """ - @spec is_java(binary()) :: boolean() - def is_java(<<0x43, 0x41, 0x76, 0x45, 0x42, 0x01, 0x42, 0x45, _rest::binary>>), do: true - def is_java(<<0x43, 0x41, 0x76, 0x45, 0x44, 0x30, 0x30, 0x44, _rest::binary>>), do: true - def is_java(_binary), do: false + @spec java?(binary()) :: boolean() + def java?(<<0x43, 0x41, 0x76, 0x45, 0x42, 0x01, 0x42, 0x45, _rest::binary>>), do: true + def java?(<<0x43, 0x41, 0x76, 0x45, 0x44, 0x30, 0x30, 0x44, _rest::binary>>), do: true + def java?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's LLVM bitcode. """ - @spec is_llvm(binary()) :: boolean() - def is_llvm(<<0x42, 0x43, _rest::binary>>), do: true - def is_llvm(_binary), do: false + @spec llvm?(binary()) :: boolean() + def llvm?(<<0x42, 0x43, _rest::binary>>), do: true + def llvm?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Mach-O binary. @@ -107,49 +107,49 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample_mach_fat") - iex> Infer.App.is_mach(binary) + iex> Infer.App.mach?(binary) true iex> binary = File.read!("test/app/sample_mach_ppc") - iex> Infer.App.is_mach(binary) + iex> Infer.App.mach?(binary) true iex> binary = File.read!("test/app/sample_mach_x64") - iex> Infer.App.is_mach(binary) + iex> Infer.App.mach?(binary) true iex> binary = File.read!("test/app/sample_mach_x86") - iex> Infer.App.is_mach(binary) + iex> Infer.App.mach?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_mach(binary) + iex> Infer.App.mach?(binary) false """ - @spec is_mach(binary()) :: boolean() - def is_mach(<>) when width in [0xCF, 0xCE], do: true - def is_mach(<<0xFE, 0xED, 0xFA, width, _rest::binary>>) when width in [0xCF, 0xCE], do: true - def is_mach(<<0xCA, 0xFE, 0xBA, 0xBE, _rest::binary>>), do: true - def is_mach(_binary), do: false + @spec mach?(binary()) :: boolean() + def mach?(<>) when width in [0xCF, 0xCE], do: true + def mach?(<<0xFE, 0xED, 0xFA, width, _rest::binary>>) when width in [0xCF, 0xCE], do: true + def mach?(<<0xCA, 0xFE, 0xBA, 0xBE, _rest::binary>>), do: true + def mach?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Dalvik Executable (DEX). See: https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic """ - @spec is_dex(binary()) :: boolean() - def is_dex(<<0x64, 0x65, 0x78, 0x0A, _data::binary-size(32), 0x70, _rest::binary>>), do: true - def is_dex(_binary), do: false + @spec dex?(binary()) :: boolean() + def dex?(<<0x64, 0x65, 0x78, 0x0A, _data::binary-size(32), 0x70, _rest::binary>>), do: true + def dex?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Optimized Dalvik Executable (ODEX). See: https://source.android.com/devices/tech/dalvik/dex-format#dex-file-magic """ - @spec is_dey(binary()) :: boolean() - def is_dey(<<0x64, 0x65, 0x79, 0x0A, _data::binary-size(36), dex::binary-size(60), _rest::binary>>), do: is_dex(dex) - def is_dey(_binary), do: false + @spec dey?(binary()) :: boolean() + def dey?(<<0x64, 0x65, 0x79, 0x0A, _data::binary-size(36), dex::binary-size(60), _rest::binary>>), do: dex?(dex) + def dey?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a DER encoded X.509 certificate. @@ -160,42 +160,42 @@ defmodule Infer.App do ## Examples iex> binary = File.read!("test/app/sample.der") - iex> Infer.App.is_der(binary) + iex> Infer.App.der?(binary) true iex> binary = File.read!("test/app/sample.wasm") - iex> Infer.App.is_der(binary) + iex> Infer.App.der?(binary) false """ - @spec is_der(binary()) :: boolean() - def is_der(<<0x30, 0x82, _rest::binary>>), do: true - def is_der(_binary), do: false + @spec der?(binary()) :: boolean() + def der?(<<0x30, 0x82, _rest::binary>>), do: true + def der?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Common Object File Format for i386 architecture. """ - @spec is_coff_i386(binary()) :: boolean() - def is_coff_i386(<<0x4C, 0x01, _rest::binary>>), do: true - def is_coff_i386(_binary), do: false + @spec coff_i386?(binary()) :: boolean() + def coff_i386?(<<0x4C, 0x01, _rest::binary>>), do: true + def coff_i386?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Common Object File Format for x64 architecture. """ - @spec is_coff_x64(binary()) :: boolean() - def is_coff_x64(<<0x64, 0x86, _rest::binary>>), do: true - def is_coff_x64(_binary), do: false + @spec coff_x64?(binary()) :: boolean() + def coff_x64?(<<0x64, 0x86, _rest::binary>>), do: true + def coff_x64?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Common Object File Format for Itanium architecture. """ - @spec is_coff_ia64(binary()) :: boolean() - def is_coff_ia64(<<0x00, 0x02, _rest::binary>>), do: true - def is_coff_ia64(_binary), do: false + @spec coff_ia64?(binary()) :: boolean() + def coff_ia64?(<<0x00, 0x02, _rest::binary>>), do: true + def coff_ia64?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Common Object File Format. """ - @spec is_coff(binary()) :: boolean() - def is_coff(binary), do: is_coff_x64(binary) || is_coff_i386(binary) || is_coff_ia64(binary) + @spec coff?(binary()) :: boolean() + def coff?(binary), do: coff_x64?(binary) || coff_i386?(binary) || coff_ia64?(binary) end diff --git a/lib/matchers/archive.ex b/lib/matchers/archive.ex index 399589f..bc614e5 100644 --- a/lib/matchers/archive.ex +++ b/lib/matchers/archive.ex @@ -3,7 +3,7 @@ defmodule Infer.Archive do Archive type matchers based on the [magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)) """ - defdelegate is_epub(binary), to: Infer.Book + defdelegate epub?(binary), to: Infer.Book @doc """ Takes the binary file contents as arguments. Returns `true` if it's a zip archive. @@ -13,51 +13,51 @@ defmodule Infer.Archive do ## Examples iex> binary = File.read!("test/archives/sample.zip") - iex> Infer.Archive.is_zip(binary) + iex> Infer.Archive.zip?(binary) true """ - @spec is_zip(binary()) :: boolean() - def is_zip(<<0x50, 0x4B, 0x3, 0x4, _rest::binary>>), do: true - def is_zip(<<0x50, 0x4B, 0x5, 0x6, _rest::binary>>), do: true - def is_zip(<<0x50, 0x4B, 0x7, 0x8, _rest::binary>>), do: true - def is_zip(_binary), do: false + @spec zip?(binary()) :: boolean() + def zip?(<<0x50, 0x4B, 0x3, 0x4, _rest::binary>>), do: true + def zip?(<<0x50, 0x4B, 0x5, 0x6, _rest::binary>>), do: true + def zip?(<<0x50, 0x4B, 0x7, 0x8, _rest::binary>>), do: true + def zip?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a tar archive. """ - @spec is_tar(binary()) :: boolean() - def is_tar(<<_data::binary-size(257), 0x75, 0x73, 0x74, 0x61, 0x72, _rest::binary>>), do: true - def is_tar(_binary), do: false + @spec tar?(binary()) :: boolean() + def tar?(<<_data::binary-size(257), 0x75, 0x73, 0x74, 0x61, 0x72, _rest::binary>>), do: true + def tar?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a rar archive. """ - @spec is_rar(binary()) :: boolean() - def is_rar(<<0x52, 0x61, 0x72, 0x21, 0x1A, 0x7, 0x0, _rest::binary>>), do: true - def is_rar(<<0x52, 0x61, 0x72, 0x21, 0x1A, 0x7, 0x1, _rest::binary>>), do: true - def is_rar(_binary), do: false + @spec rar?(binary()) :: boolean() + def rar?(<<0x52, 0x61, 0x72, 0x21, 0x1A, 0x7, 0x0, _rest::binary>>), do: true + def rar?(<<0x52, 0x61, 0x72, 0x21, 0x1A, 0x7, 0x1, _rest::binary>>), do: true + def rar?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a gzip archive. """ - @spec is_gz(binary()) :: boolean() - def is_gz(<<0x1F, 0x8B, 0x8, _rest::binary>>), do: true - def is_gz(_binary), do: false + @spec gz?(binary()) :: boolean() + def gz?(<<0x1F, 0x8B, 0x8, _rest::binary>>), do: true + def gz?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a bzip archive. """ - @spec is_bz2(binary()) :: boolean() - def is_bz2(<<0x42, 0x5A, 0x68, _rest::binary>>), do: true - def is_bz2(_binary), do: false + @spec bz2?(binary()) :: boolean() + def bz2?(<<0x42, 0x5A, 0x68, _rest::binary>>), do: true + def bz2?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a 7z archive. """ - @spec is_7z(binary()) :: boolean() - def is_7z(<<0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C, _rest::binary>>), do: true - def is_7z(_binary), do: false + @spec sevenz?(binary()) :: boolean() + def sevenz?(<<0x37, 0x7A, 0xBC, 0xAF, 0x27, 0x1C, _rest::binary>>), do: true + def sevenz?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a pdf. @@ -65,72 +65,72 @@ defmodule Infer.Archive do ## Examples iex> binary = File.read!("test/archives/sample.pdf") - iex> Infer.Archive.is_pdf(binary) + iex> Infer.Archive.pdf?(binary) true """ - @spec is_pdf(binary()) :: boolean() - def is_pdf(<<0x25, 0x50, 0x44, 0x46, _rest::binary>>), do: true - def is_pdf(_binary), do: false + @spec pdf?(binary()) :: boolean() + def pdf?(<<0x25, 0x50, 0x44, 0x46, _rest::binary>>), do: true + def pdf?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a swf. """ - @spec is_swf(binary()) :: boolean() - def is_swf(<<0x43, 0x57, 0x53, _rest::binary>>), do: true - def is_swf(<<0x46, 0x57, 0x53, _rest::binary>>), do: true - def is_swf(_binary), do: false + @spec swf?(binary()) :: boolean() + def swf?(<<0x43, 0x57, 0x53, _rest::binary>>), do: true + def swf?(<<0x46, 0x57, 0x53, _rest::binary>>), do: true + def swf?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a rtf. """ - @spec is_rtf(binary()) :: boolean() - def is_rtf(<<0x7B, 0x5C, 0x72, 0x74, 0x66, _rest::binary>>), do: true - def is_rtf(_binary), do: false + @spec rtf?(binary()) :: boolean() + def rtf?(<<0x7B, 0x5C, 0x72, 0x74, 0x66, _rest::binary>>), do: true + def rtf?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Nintendo NES ROM. """ - @spec is_nes(binary()) :: boolean() - def is_nes(<<0x4E, 0x45, 0x53, 0x1A, _rest::binary>>), do: true - def is_nes(_binary), do: false + @spec nes?(binary()) :: boolean() + def nes?(<<0x4E, 0x45, 0x53, 0x1A, _rest::binary>>), do: true + def nes?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Google Chrome Extension. """ - @spec is_crx(binary()) :: boolean() - def is_crx(<<0x43, 0x72, 0x32, 0x34, _rest::binary>>), do: true - def is_crx(_binary), do: false + @spec crx?(binary()) :: boolean() + def crx?(<<0x43, 0x72, 0x32, 0x34, _rest::binary>>), do: true + def crx?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a CAB. """ - @spec is_cab(binary()) :: boolean() - def is_cab(<<0x4D, 0x53, 0x43, 0x46, _rest::binary>>), do: true - def is_cab(<<0x49, 0x53, 0x63, 0x28, _rest::binary>>), do: true - def is_cab(_binary), do: false + @spec cab?(binary()) :: boolean() + def cab?(<<0x4D, 0x53, 0x43, 0x46, _rest::binary>>), do: true + def cab?(<<0x49, 0x53, 0x63, 0x28, _rest::binary>>), do: true + def cab?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a eot octet stream. """ - @spec is_eot(binary()) :: boolean() - def is_eot(<<_header::binary-size(8), 0x01, 0x00, 0x00, _data::binary-size(24), 0x4C, 0x50, _rest::binary>>), do: true - def is_eot(<<_header::binary-size(8), 0x02, 0x00, 0x02, _data::binary-size(24), 0x4C, 0x50, _rest::binary>>), do: true - def is_eot(_binary), do: false + @spec eot?(binary()) :: boolean() + def eot?(<<_header::binary-size(8), 0x01, 0x00, 0x00, _data::binary-size(24), 0x4C, 0x50, _rest::binary>>), do: true + def eot?(<<_header::binary-size(8), 0x02, 0x00, 0x02, _data::binary-size(24), 0x4C, 0x50, _rest::binary>>), do: true + def eot?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a postscript. """ - @spec is_ps(binary()) :: boolean() - def is_ps(<<0x25, 0x21, _rest::binary>>), do: true - def is_ps(_binary), do: false + @spec ps?(binary()) :: boolean() + def ps?(<<0x25, 0x21, _rest::binary>>), do: true + def ps?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a xz archive. """ - @spec is_xz(binary()) :: boolean() - def is_xz(<<0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00, _rest::binary>>), do: true - def is_xz(_binary), do: false + @spec xz?(binary()) :: boolean() + def xz?(<<0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00, _rest::binary>>), do: true + def xz?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a sqlite3 database. @@ -139,61 +139,61 @@ defmodule Infer.Archive do ## Examples iex> binary = File.read!("test/archives/sample.db") - iex> Infer.Archive.is_sqlite(binary) + iex> Infer.Archive.sqlite?(binary) true """ - @spec is_sqlite(binary()) :: boolean() - def is_sqlite(<<0x53, 0x51, 0x4C, 0x69, _rest::binary>>), do: true - def is_sqlite(_binary), do: false + @spec sqlite?(binary()) :: boolean() + def sqlite?(<<0x53, 0x51, 0x4C, 0x69, _rest::binary>>), do: true + def sqlite?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a deb archive. """ - @spec is_deb(binary()) :: boolean() - def is_deb( + @spec deb?(binary()) :: boolean() + def deb?( <<0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, 0x0A, 0x64, 0x65, 0x62, 0x69, 0x61, 0x6E, 0x2D, 0x62, 0x69, 0x6E, 0x61, 0x72, 0x79, _rest::binary>> ), do: true - def is_deb(_binary), do: false + def deb?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a ar archive. """ - @spec is_ar(binary()) :: boolean() - def is_ar(<<0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, _rest::binary>>), do: true - def is_ar(_binary), do: false + @spec ar?(binary()) :: boolean() + def ar?(<<0x21, 0x3C, 0x61, 0x72, 0x63, 0x68, 0x3E, _rest::binary>>), do: true + def ar?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a z archive. """ - @spec is_z(binary()) :: boolean() - def is_z(<<0x1F, 0xA0, _rest::binary>>), do: true - def is_z(<<0x1F, 0x9D, _rest::binary>>), do: true - def is_z(_binary), do: false + @spec z?(binary()) :: boolean() + def z?(<<0x1F, 0xA0, _rest::binary>>), do: true + def z?(<<0x1F, 0x9D, _rest::binary>>), do: true + def z?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a lzip archive. """ - @spec is_lz(binary()) :: boolean() - def is_lz(<<0x4C, 0x5A, 0x49, 0x50, _rest::binary>>), do: true - def is_lz(_binary), do: false + @spec lz?(binary()) :: boolean() + def lz?(<<0x4C, 0x5A, 0x49, 0x50, _rest::binary>>), do: true + def lz?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a RPM. """ - @spec is_rpm(binary()) :: boolean() - def is_rpm(<<0xED, 0xAB, 0xEE, 0xDB, _rest::binary>> = binary) when byte_size(binary) < 96, do: true - def is_rpm(_binary), do: false + @spec rpm?(binary()) :: boolean() + def rpm?(<<0xED, 0xAB, 0xEE, 0xDB, _rest::binary>> = binary) when byte_size(binary) < 96, do: true + def rpm?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a dcm archive. """ - @spec is_dcm(binary()) :: boolean() - def is_dcm(<<_data::binary-size(128), 0x44, 0x49, 0x43, 0x4D, _rest::binary>>), do: true - def is_dcm(_binary), do: false + @spec dcm?(binary()) :: boolean() + def dcm?(<<_data::binary-size(128), 0x44, 0x49, 0x43, 0x4D, _rest::binary>>), do: true + def dcm?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a Zstd archive. @@ -201,18 +201,18 @@ defmodule Infer.Archive do ## Examples iex> binary = File.read!("test/archives/sample.tar.zst") - iex> Infer.Archive.is_zst(binary) + iex> Infer.Archive.zst?(binary) true """ - @spec is_zst(binary()) :: boolean() - def is_zst(<<0x28, 0xB5, 0x2F, 0xFD, _rest::binary>>), do: true - def is_zst(_binary), do: false + @spec zst?(binary()) :: boolean() + def zst?(<<0x28, 0xB5, 0x2F, 0xFD, _rest::binary>>), do: true + def zst?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a MSI windows installer archive. """ - @spec is_msi(binary()) :: boolean() - def is_msi(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>>), do: true - def is_msi(_binary), do: false + @spec msi?(binary()) :: boolean() + def msi?(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>>), do: true + def msi?(_binary), do: false end diff --git a/lib/matchers/audio.ex b/lib/matchers/audio.ex index 74c5ac9..6efc99f 100644 --- a/lib/matchers/audio.ex +++ b/lib/matchers/audio.ex @@ -6,9 +6,9 @@ defmodule Infer.Audio do @doc """ Takes the binary file contents as arguments. Returns `true` if it's a midi. """ - @spec is_midi(binary()) :: boolean() - def is_midi(<<0x4D, 0x54, 0x68, 0x64, _rest::binary>>), do: true - def is_midi(_binary), do: false + @spec midi?(binary()) :: boolean() + def midi?(<<0x4D, 0x54, 0x68, 0x64, _rest::binary>>), do: true + def midi?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mp3. @@ -16,62 +16,62 @@ defmodule Infer.Audio do ## Examples iex> binary = File.read!("test/audio/sample.mp3") - iex> Infer.Audio.is_mp3(binary) + iex> Infer.Audio.mp3?(binary) true """ - @spec is_mp3(binary()) :: boolean() - def is_mp3(<<0x49, 0x44, 0x33, _rest::binary>>), do: true - def is_mp3(<<0xFF, 0xFB, _rest::binary>>), do: true - def is_mp3(_binary), do: false + @spec mp3?(binary()) :: boolean() + def mp3?(<<0x49, 0x44, 0x33, _rest::binary>>), do: true + def mp3?(<<0xFF, 0xFB, _rest::binary>>), do: true + def mp3?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a m4a. """ - @spec is_m4a(binary()) :: boolean() - def is_m4a(<<_data::binary-size(4), 0x66, 0x74, 0x79, 0x70, 0x4D, 0x3F, 0x41, _rest::binary>>), do: true - def is_m4a(<<0x4D, 0x34, 0x41, 0x20, _rest::binary>>), do: true - def is_m4a(_binary), do: false + @spec m4a?(binary()) :: boolean() + def m4a?(<<_data::binary-size(4), 0x66, 0x74, 0x79, 0x70, 0x4D, 0x3F, 0x41, _rest::binary>>), do: true + def m4a?(<<0x4D, 0x34, 0x41, 0x20, _rest::binary>>), do: true + def m4a?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a ogg. """ - @spec is_ogg(binary()) :: boolean() - def is_ogg(<<0x4F, 0x67, 0x67, 0x53, _rest::binary>>), do: true - def is_ogg(_binary), do: false + @spec ogg?(binary()) :: boolean() + def ogg?(<<0x4F, 0x67, 0x67, 0x53, _rest::binary>>), do: true + def ogg?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a flac. """ - @spec is_flac(binary()) :: boolean() - def is_flac(<<0x66, 0x4C, 0x61, 0x43, _rest::binary>>), do: true - def is_flac(_binary), do: false + @spec flac?(binary()) :: boolean() + def flac?(<<0x66, 0x4C, 0x61, 0x43, _rest::binary>>), do: true + def flac?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a wav. """ - @spec is_wav(binary()) :: boolean() - def is_wav(<<0x52, 0x49, 0x46, 0x46, _data::binary-size(4), 0x57, 0x41, 0x56, 0x45, _rest::binary>>), do: true - def is_wav(_binary), do: false + @spec wav?(binary()) :: boolean() + def wav?(<<0x52, 0x49, 0x46, 0x46, _data::binary-size(4), 0x57, 0x41, 0x56, 0x45, _rest::binary>>), do: true + def wav?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a amr. """ - @spec is_amr(binary()) :: boolean() - def is_amr(<<0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A, _rest::binary>>), do: true - def is_amr(_binary), do: false + @spec amr?(binary()) :: boolean() + def amr?(<<0x23, 0x21, 0x41, 0x4D, 0x52, 0x0A, _rest::binary>>), do: true + def amr?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a aac. """ - @spec is_aac(binary()) :: boolean() - def is_aac(<<0xFF, 0xF1, 0xF9, _rest::binary>>), do: true - def is_aac(_binary), do: false + @spec aac?(binary()) :: boolean() + def aac?(<<0xFF, 0xF1, 0xF9, _rest::binary>>), do: true + def aac?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's an aiff. """ - @spec is_aiff(binary()) :: boolean() - def is_aiff(<<0x46, 0x4F, 0x52, 0x4D, _data::binary-size(4), 0x41, 0x49, 0x46, 0x46, _rest::binary>>), do: true - def is_aiff(_binary), do: false + @spec aiff?(binary()) :: boolean() + def aiff?(<<0x46, 0x4F, 0x52, 0x4D, _data::binary-size(4), 0x41, 0x49, 0x46, 0x46, _rest::binary>>), do: true + def aiff?(_binary), do: false end diff --git a/lib/matchers/book.ex b/lib/matchers/book.ex index 5d230b9..da58274 100644 --- a/lib/matchers/book.ex +++ b/lib/matchers/book.ex @@ -9,22 +9,22 @@ defmodule Infer.Book do ## Examples iex> binary = File.read!("test/books/sample.epub") - iex> Infer.Book.is_epub(binary) + iex> Infer.Book.epub?(binary) true iex> binary = File.read!("test/books/sample.mobi") - iex> Infer.Book.is_epub(binary) + iex> Infer.Book.epub?(binary) false """ - @spec is_epub(binary()) :: boolean() - def is_epub( + @spec epub?(binary()) :: boolean() + def epub?( <<0x50, 0x4B, 0x3, 0x4, _data::binary-size(26), 0x6D, 0x69, 0x6D, 0x65, 0x74, 0x79, 0x70, 0x65, 0x61, 0x70, 0x70, 0x6C, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2F, 0x65, 0x70, 0x75, 0x62, 0x2B, 0x7A, 0x69, 0x70, _rest::binary>> ), do: true - def is_epub(_binary), do: false + def epub?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mobi. @@ -32,15 +32,15 @@ defmodule Infer.Book do ## Examples iex> binary = File.read!("test/books/sample.mobi") - iex> Infer.Book.is_mobi(binary) + iex> Infer.Book.mobi?(binary) true iex> binary = File.read!("test/books/sample.epub") - iex> Infer.Book.is_mobi(binary) + iex> Infer.Book.mobi?(binary) false """ - @spec is_mobi(binary()) :: boolean() - def is_mobi(<<_data::binary-size(60), 0x42, 0x4F, 0x4F, 0x4B, 0x4D, 0x4F, 0x42, 0x49, _rest::binary>>), do: true - def is_mobi(_binary), do: false + @spec mobi?(binary()) :: boolean() + def mobi?(<<_data::binary-size(60), 0x42, 0x4F, 0x4F, 0x4B, 0x4D, 0x4F, 0x42, 0x49, _rest::binary>>), do: true + def mobi?(_binary), do: false end diff --git a/lib/matchers/doc.ex b/lib/matchers/doc.ex index 6aab34a..cddb8f2 100644 --- a/lib/matchers/doc.ex +++ b/lib/matchers/doc.ex @@ -11,17 +11,17 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.docx") - iex> Infer.Doc.is_docx(binary) + iex> Infer.Doc.docx?(binary) true iex> binary = File.read!("test/docs/sample.xlsx") - iex> Infer.Doc.is_docx(binary) + iex> Infer.Doc.docx?(binary) false """ - @spec is_docx(binary()) :: boolean() - def is_docx(<>), do: true - def is_docx(binary), do: msooxml(binary) == :docx + @spec docx?(binary()) :: boolean() + def docx?(<>), do: true + def docx?(binary), do: msooxml?(binary) == :docx @doc """ Takes the binary file contents as arguments. Returns `true` if it's Microsoft Excel Open XML Format Spreadsheet (XLSX) data. @@ -29,17 +29,17 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.xlsx") - iex> Infer.Doc.is_xlsx(binary) + iex> Infer.Doc.xlsx?(binary) true iex> binary = File.read!("test/docs/sample.docx") - iex> Infer.Doc.is_xlsx(binary) + iex> Infer.Doc.xlsx?(binary) false """ - @spec is_xlsx(binary()) :: boolean() - def is_xlsx(<>), do: true - def is_xlsx(binary), do: msooxml(binary) == :xlsx + @spec xlsx?(binary()) :: boolean() + def xlsx?(<>), do: true + def xlsx?(binary), do: msooxml?(binary) == :xlsx @doc """ Takes the binary file contents as arguments. Returns `true` if it's Microsoft PowerPoint Open XML Presentation (PPTX) data. @@ -47,34 +47,34 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.pptx") - iex> Infer.Doc.is_pptx(binary) + iex> Infer.Doc.pptx?(binary) true iex> binary = File.read!("test/docs/sample.xlsx") - iex> Infer.Doc.is_pptx(binary) + iex> Infer.Doc.pptx?(binary) false """ - @spec is_pptx(binary()) :: boolean() - def is_pptx(<>), do: true - def is_pptx(binary), do: msooxml(binary) == :pptx + @spec pptx?(binary()) :: boolean() + def pptx?(<>), do: true + def pptx?(binary), do: msooxml?(binary) == :pptx - defp msooxml(<> = binary) do + defp msooxml?(<> = binary) do {:ok, parts} = :zip.unzip(binary, [:memory]) search_x_format(parts) end - defp msooxml(<> = binary) do + defp msooxml?(<> = binary) do {:ok, parts} = :zip.unzip(binary, [:memory]) search_x_format(parts) end - defp msooxml(<> = binary) do + defp msooxml?(<> = binary) do {:ok, parts} = :zip.unzip(binary, [:memory]) search_x_format(parts) end - defp msooxml(_binary), do: nil + defp msooxml?(_binary), do: nil defp search_x_format([_, _, {[?w, ?o, ?r, ?d, ?/ | _], _} | _]), do: :docx defp search_x_format([_, _, {[?x, ?l, ?/ | _], _} | _]), do: :xlsx @@ -90,19 +90,19 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.odt") - iex> Infer.Doc.is_odt(binary) + iex> Infer.Doc.odt?(binary) true iex> binary = File.read!("test/docs/sample.odt") - iex> Infer.Doc.is_pptx(binary) + iex> Infer.Doc.pptx?(binary) false """ - @spec is_odt(binary()) :: boolean() - def is_odt(<>), + @spec odt?(binary()) :: boolean() + def odt?(<>), do: true - def is_odt(_binary), do: false + def odt?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's an OpenDocument Spreadsheet Document. @@ -110,19 +110,19 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.ods") - iex> Infer.Doc.is_ods(binary) + iex> Infer.Doc.ods?(binary) true iex> binary = File.read!("test/docs/sample.ods") - iex> Infer.Doc.is_odt(binary) + iex> Infer.Doc.odt?(binary) false """ - @spec is_ods(binary()) :: boolean() - def is_ods(<>), + @spec ods?(binary()) :: boolean() + def ods?(<>), do: true - def is_ods(_binary), do: false + def ods?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's an OpenDocument Presentation Document. @@ -130,19 +130,19 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.odp") - iex> Infer.Doc.is_odp(binary) + iex> Infer.Doc.odp?(binary) true iex> binary = File.read!("test/docs/sample.odp") - iex> Infer.Doc.is_odt(binary) + iex> Infer.Doc.odt?(binary) false """ - @spec is_odp(binary()) :: boolean() - def is_odp(<>), + @spec odp?(binary()) :: boolean() + def odp?(<>), do: true - def is_odp(_binary), do: false + def odp?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's Microsoft Word Document (DOC) data. @@ -150,17 +150,17 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.doc") - iex> Infer.Doc.is_doc(binary) + iex> Infer.Doc.doc?(binary) true iex> binary = File.read!("test/docs/sample.docx") - iex> Infer.Doc.is_doc(binary) + iex> Infer.Doc.doc?(binary) false """ - @spec is_doc(binary()) :: boolean() - def is_doc(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = doc), do: search_format(doc) == :doc - def is_doc(_binary), do: false + @spec doc?(binary()) :: boolean() + def doc?(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = doc), do: search_format(doc) == :doc + def doc?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's Microsoft Power Point Document (PPT) data. @@ -168,17 +168,17 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.ppt") - iex> Infer.Doc.is_ppt(binary) + iex> Infer.Doc.ppt?(binary) true iex> binary = File.read!("test/docs/sample.doc") - iex> Infer.Doc.is_ppt(binary) + iex> Infer.Doc.ppt?(binary) false """ - @spec is_ppt(binary()) :: boolean() - def is_ppt(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = ppt), do: search_format(ppt) == :ppt - def is_ppt(_binary), do: false + @spec ppt?(binary()) :: boolean() + def ppt?(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = ppt), do: search_format(ppt) == :ppt + def ppt?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's Microsoft Excel (XLS) data. @@ -186,17 +186,17 @@ defmodule Infer.Doc do ## Examples iex> binary = File.read!("test/docs/sample.xls") - iex> Infer.Doc.is_xls(binary) + iex> Infer.Doc.xls?(binary) true iex> binary = File.read!("test/docs/sample.doc") - iex> Infer.Doc.is_xls(binary) + iex> Infer.Doc.xls?(binary) false """ - @spec is_xls(binary()) :: boolean() - def is_xls(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = ppt), do: search_format(ppt) == :xls - def is_xls(_binary), do: false + @spec xls?(binary()) :: boolean() + def xls?(<<0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, _rest::binary>> = ppt), do: search_format(ppt) == :xls + def xls?(_binary), do: false defp search_format( <<_header::binary-size(30), sector_size::binary-size(2), _dir_offset::binary-size(16), root_directory_index::binary-size(4), diff --git a/lib/matchers/font.ex b/lib/matchers/font.ex index 8be3ba9..8693ba3 100644 --- a/lib/matchers/font.ex +++ b/lib/matchers/font.ex @@ -6,16 +6,16 @@ defmodule Infer.Font do @doc """ Takes the binary file contents as arguments. Returns `true` if it's a woff font. """ - @spec is_woff(binary()) :: boolean() - def is_woff(<<0x77, 0x4F, 0x46, 0x46, 0x00, 0x01, 0x00, 0x00, _rest::binary>>), do: true - def is_woff(_binary), do: false + @spec woff?(binary()) :: boolean() + def woff?(<<0x77, 0x4F, 0x46, 0x46, 0x00, 0x01, 0x00, 0x00, _rest::binary>>), do: true + def woff?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a woff2 font. """ - @spec is_woff2(binary()) :: boolean() - def is_woff2(<<0x77, 0x4F, 0x46, 0x32, 0x00, 0x01, 0x00, 0x00, _rest::binary>>), do: true - def is_woff2(_binary), do: false + @spec woff2?(binary()) :: boolean() + def woff2?(<<0x77, 0x4F, 0x46, 0x32, 0x00, 0x01, 0x00, 0x00, _rest::binary>>), do: true + def woff2?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a ttf font. @@ -23,18 +23,18 @@ defmodule Infer.Font do ## Examples iex> binary = File.read!("test/fonts/sample.ttf") - iex> Infer.Font.is_ttf(binary) + iex> Infer.Font.ttf?(binary) true """ - @spec is_ttf(binary()) :: boolean() - def is_ttf(<<0x00, 0x01, 0x00, 0x00, 0x00, _rest::binary>>), do: true - def is_ttf(_binary), do: false + @spec ttf?(binary()) :: boolean() + def ttf?(<<0x00, 0x01, 0x00, 0x00, 0x00, _rest::binary>>), do: true + def ttf?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a otf font. """ - @spec is_otf(binary()) :: boolean() - def is_otf(<<0x4F, 0x54, 0x54, 0x4F, 0x00>>), do: true - def is_otf(_binary), do: false + @spec otf?(binary()) :: boolean() + def otf?(<<0x4F, 0x54, 0x54, 0x4F, 0x00>>), do: true + def otf?(_binary), do: false end diff --git a/lib/matchers/image.ex b/lib/matchers/image.ex index b7852f9..affe952 100644 --- a/lib/matchers/image.ex +++ b/lib/matchers/image.ex @@ -9,17 +9,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.jpg") - iex> Infer.Image.is_jpeg(binary) + iex> Infer.Image.jpeg?(binary) true iex> binary = File.read!("test/images/sample.jp2") - iex> Infer.Image.is_jpeg(binary) + iex> Infer.Image.jpeg?(binary) false """ - @spec is_jpeg(binary()) :: boolean() - def is_jpeg(<<0xFF, 0xD8, 0xFF>> <> _), do: true - def is_jpeg(_binary), do: false + @spec jpeg?(binary()) :: boolean() + def jpeg?(<<0xFF, 0xD8, 0xFF>> <> _), do: true + def jpeg?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a jpeg2000. @@ -27,17 +27,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.jp2") - iex> Infer.Image.is_jpeg2000(binary) + iex> Infer.Image.jpeg2000?(binary) true iex> binary = File.read!("test/images/sample.jpg") - iex> Infer.Image.is_jpeg2000(binary) + iex> Infer.Image.jpeg2000?(binary) false """ - @spec is_jpeg2000(binary()) :: boolean() - def is_jpeg2000(<<0x0, 0x0, 0x0, 0xC, 0x6A, 0x50, 0x20, 0x20, 0xD, 0xA, 0x87, 0xA, 0x0, _rest::binary>>), do: true - def is_jpeg2000(_binary), do: false + @spec jpeg2000?(binary()) :: boolean() + def jpeg2000?(<<0x0, 0x0, 0x0, 0xC, 0x6A, 0x50, 0x20, 0x20, 0xD, 0xA, 0x87, 0xA, 0x0, _rest::binary>>), do: true + def jpeg2000?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a png. @@ -45,17 +45,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.png") - iex> Infer.Image.is_png(binary) + iex> Infer.Image.png?(binary) true iex> binary = File.read!("test/images/sample.jpg") - iex> Infer.Image.is_png(binary) + iex> Infer.Image.png?(binary) false """ - @spec is_png(binary()) :: boolean() - def is_png(<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _rest::binary>>), do: true - def is_png(_binary), do: false + @spec png?(binary()) :: boolean() + def png?(<<0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, _rest::binary>>), do: true + def png?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a gif. @@ -63,17 +63,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.gif") - iex> Infer.Image.is_gif(binary) + iex> Infer.Image.gif?(binary) true iex> binary = File.read!("test/images/sample.jpg") - iex> Infer.Image.is_gif(binary) + iex> Infer.Image.gif?(binary) false """ - @spec is_gif(binary()) :: boolean() - def is_gif(<<0x47, 0x49, 0x46, _rest::binary>>), do: true - def is_gif(_binary), do: false + @spec gif?(binary()) :: boolean() + def gif?(<<0x47, 0x49, 0x46, _rest::binary>>), do: true + def gif?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a webp. @@ -81,17 +81,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.webp") - iex> Infer.Image.is_webp(binary) + iex> Infer.Image.webp?(binary) true iex> binary = File.read!("test/images/sample.gif") - iex> Infer.Image.is_webp(binary) + iex> Infer.Image.webp?(binary) false """ - @spec is_webp(binary()) :: boolean() - def is_webp(<<_head::binary-size(8), 0x57, 0x45, 0x42, 0x50, _rest::binary>>), do: true - def is_webp(_binary), do: false + @spec webp?(binary()) :: boolean() + def webp?(<<_head::binary-size(8), 0x57, 0x45, 0x42, 0x50, _rest::binary>>), do: true + def webp?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a cr2. @@ -99,18 +99,18 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.cr2") - iex> Infer.Image.is_cr2(binary) + iex> Infer.Image.cr2?(binary) true iex> binary = File.read!("test/images/sample.tiff") - iex> Infer.Image.is_cr2(binary) + iex> Infer.Image.cr2?(binary) false """ - @spec is_cr2(binary()) :: boolean() - def is_cr2(<<0x49, 0x49, 0x2A, 0x0, _data::binary-size(4), 0x43, 0x52, 0x02, _rest::binary>>), do: true - def is_cr2(<<0x4D, 0x4D, 0x0, 0x2A, _data::binary-size(4), 0x43, 0x52, 0x02, _rest::binary>>), do: true - def is_cr2(_binary), do: false + @spec cr2?(binary()) :: boolean() + def cr2?(<<0x49, 0x49, 0x2A, 0x0, _data::binary-size(4), 0x43, 0x52, 0x02, _rest::binary>>), do: true + def cr2?(<<0x4D, 0x4D, 0x0, 0x2A, _data::binary-size(4), 0x43, 0x52, 0x02, _rest::binary>>), do: true + def cr2?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a tiff. @@ -118,22 +118,22 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.tiff") - iex> Infer.Image.is_tiff(binary) + iex> Infer.Image.tiff?(binary) true iex> binary = File.read!("test/images/sample.cr2") - iex> Infer.Image.is_tiff(binary) + iex> Infer.Image.tiff?(binary) false """ - @spec is_tiff(binary()) :: boolean() - def is_tiff(<<0x49, 0x49, 0x2A, 0x0, _data::binary-size(4), i_8, i_9, _rest::binary>> = binary) when i_8 != <<0x43>> and i_9 != <<0x52>>, - do: !is_cr2(binary) + @spec tiff?(binary()) :: boolean() + def tiff?(<<0x49, 0x49, 0x2A, 0x0, _data::binary-size(4), i_8, i_9, _rest::binary>> = binary) when i_8 != <<0x43>> and i_9 != <<0x52>>, + do: !cr2?(binary) - def is_tiff(<<0x4D, 0x4D, 0x0, 0x2A, _data::binary-size(4), i_8, i_9, _rest::binary>> = binary) when i_8 != <<0x43>> and i_9 != <<0x52>>, - do: !is_cr2(binary) + def tiff?(<<0x4D, 0x4D, 0x0, 0x2A, _data::binary-size(4), i_8, i_9, _rest::binary>> = binary) when i_8 != <<0x43>> and i_9 != <<0x52>>, + do: !cr2?(binary) - def is_tiff(_binary), do: false + def tiff?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a bmp. @@ -141,17 +141,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.bmp") - iex> Infer.Image.is_bmp(binary) + iex> Infer.Image.bmp?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.Image.is_bmp(binary) + iex> Infer.Image.bmp?(binary) false """ - @spec is_bmp(binary()) :: boolean() - def is_bmp(<<0x42, 0x4D, _rest::binary>>), do: true - def is_bmp(_binary), do: false + @spec bmp?(binary()) :: boolean() + def bmp?(<<0x42, 0x4D, _rest::binary>>), do: true + def bmp?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a jxr. @@ -159,17 +159,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.jxr") - iex> Infer.Image.is_jxr(binary) + iex> Infer.Image.jxr?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.Image.is_jxr(binary) + iex> Infer.Image.jxr?(binary) false """ - @spec is_jxr(binary()) :: boolean() - def is_jxr(<<0x49, 0x49, 0xBC, _rest::binary>>), do: true - def is_jxr(_binary), do: false + @spec jxr?(binary()) :: boolean() + def jxr?(<<0x49, 0x49, 0xBC, _rest::binary>>), do: true + def jxr?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a psd. @@ -177,17 +177,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.psd") - iex> Infer.Image.is_psd(binary) + iex> Infer.Image.psd?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.Image.is_psd(binary) + iex> Infer.Image.psd?(binary) false """ - @spec is_psd(binary()) :: boolean() - def is_psd(<<0x38, 0x42, 0x50, 0x53, _rest::binary>>), do: true - def is_psd(_binary), do: false + @spec psd?(binary()) :: boolean() + def psd?(<<0x38, 0x42, 0x50, 0x53, _rest::binary>>), do: true + def psd?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a ico. @@ -195,17 +195,17 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.ico") - iex> Infer.Image.is_ico(binary) + iex> Infer.Image.ico?(binary) true iex> binary = File.read!("test/images/sample.png") - iex> Infer.Image.is_ico(binary) + iex> Infer.Image.ico?(binary) false """ - @spec is_ico(binary()) :: boolean() - def is_ico(<<0x00, 0x00, 0x01, 0x00, _rest::binary>>), do: true - def is_ico(_binary), do: false + @spec ico?(binary()) :: boolean() + def ico?(<<0x00, 0x00, 0x01, 0x00, _rest::binary>>), do: true + def ico?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a heif. @@ -213,16 +213,16 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.heif") - iex> Infer.Image.is_heif(binary) + iex> Infer.Image.heif?(binary) true iex> binary = File.read!("test/images/sample.avif") - iex> Infer.Image.is_heif(binary) + iex> Infer.Image.heif?(binary) false """ - @spec is_heif(binary()) :: boolean() - def is_heif(<> = binary) when bit_size(ftyp_length) >= 16 do + @spec heif?(binary()) :: boolean() + def heif?(<> = binary) when bit_size(ftyp_length) >= 16 do case get_ftyp(binary) do {"heic", _minor, _compatbile} -> true {major, _minor, compatible} when major in ["mif1", "msf1"] -> 'heic' in compatible @@ -230,7 +230,7 @@ defmodule Infer.Image do end end - def is_heif(_binary), do: false + def heif?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a avif. @@ -238,16 +238,16 @@ defmodule Infer.Image do ## Examples iex> binary = File.read!("test/images/sample.avif") - iex> Infer.Image.is_avif(binary) + iex> Infer.Image.avif?(binary) true iex> binary = File.read!("test/images/sample.heif") - iex> Infer.Image.is_avif(binary) + iex> Infer.Image.avif?(binary) false """ - @spec is_avif(binary()) :: boolean() - def is_avif(<> = binary) when bit_size(ftyp_length) >= 16 do + @spec avif?(binary()) :: boolean() + def avif?(<> = binary) when bit_size(ftyp_length) >= 16 do case get_ftyp(binary) do {major, _minor, _compatbile} when major in ["avif", "avis"] -> true {_major, _minor, compatible} -> 'avif' in compatible || 'avis' in compatible @@ -255,7 +255,7 @@ defmodule Infer.Image do end end - def is_avif(_binary), do: false + def avif?(_binary), do: false defp get_ftyp(<>) do compatible = diff --git a/lib/matchers/text.ex b/lib/matchers/text.ex index b7c05a0..bafb8c3 100644 --- a/lib/matchers/text.ex +++ b/lib/matchers/text.ex @@ -10,18 +10,18 @@ defmodule Infer.Text do ## Examples - iex> Infer.Text.is_html("") + iex> Infer.Text.html?("") true - iex> Infer.Text.is_html(" ") + iex> Infer.Text.html?(" ") true - iex> Infer.Text.is_html("<") + iex> Infer.Text.html?("<") false """ - @spec is_html(binary()) :: boolean() - def is_html(binary) do + @spec html?(binary()) :: boolean() + def html?(binary) do values = [ ' String.trim() @@ -76,9 +76,9 @@ defmodule Infer.Text do @doc """ Takes the binary file contents as arguments. Returns `true` if it's a shell script. """ - @spec is_shell_script(binary()) :: boolean() - def is_shell_script(<<"#!", _rest::binary>>), do: true - def is_shell_script(_binary), do: false + @spec shell_script?(binary()) :: boolean() + def shell_script?(<<"#!", _rest::binary>>), do: true + def shell_script?(_binary), do: false defp starts_with_ignore_ascii_case(char_list, needle) when length(char_list) >= length(needle) do char_list = Enum.take(char_list, length(needle)) diff --git a/lib/matchers/video.ex b/lib/matchers/video.ex index e9ed927..9f46969 100644 --- a/lib/matchers/video.ex +++ b/lib/matchers/video.ex @@ -6,9 +6,9 @@ defmodule Infer.Video do @doc """ Takes the binary file contents as arguments. Returns `true` if it's a m4v. """ - @spec is_m4v(binary()) :: boolean() - def is_m4v(<<_data::binary-size(4), 0x66, 0x74, 0x79, 0x70, 0x4D, 0x43, 0x56, _rest::binary>>), do: true - def is_m4v(_binary), do: false + @spec m4v?(binary()) :: boolean() + def m4v?(<<_data::binary-size(4), 0x66, 0x74, 0x79, 0x70, 0x4D, 0x43, 0x56, _rest::binary>>), do: true + def m4v?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mkv. @@ -16,14 +16,14 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.mkv") - iex> Infer.Video.is_mkv(binary) + iex> Infer.Video.mkv?(binary) true """ - @spec is_mkv(binary()) :: boolean() - def is_mkv(<<0x1A, 0x45, 0xDF, 0xA3, 0x93, 0x42, 0x82, 0x88, 0x6D, 0x61, 0x74, 0x72, 0x6F, 0x73, 0x6B, 0x61, _rest::binary>>), do: true - def is_mkv(<<_data::binary-size(31), 0x6D, 0x61, 0x74, 0x72, 0x6F, 0x73, 0x6B, 0x61, _rest::binary>>), do: true - def is_mkv(_binary), do: false + @spec mkv?(binary()) :: boolean() + def mkv?(<<0x1A, 0x45, 0xDF, 0xA3, 0x93, 0x42, 0x82, 0x88, 0x6D, 0x61, 0x74, 0x72, 0x6F, 0x73, 0x6B, 0x61, _rest::binary>>), do: true + def mkv?(<<_data::binary-size(31), 0x6D, 0x61, 0x74, 0x72, 0x6F, 0x73, 0x6B, 0x61, _rest::binary>>), do: true + def mkv?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a webm video. @@ -31,13 +31,13 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.webm") - iex> Infer.Video.is_webm(binary) + iex> Infer.Video.webm?(binary) true """ - @spec is_webm(binary()) :: boolean() - def is_webm(<<0x1A, 0x45, 0xDF, 0xA3, _rest::binary>>), do: true - def is_webm(_binary), do: false + @spec webm?(binary()) :: boolean() + def webm?(<<0x1A, 0x45, 0xDF, 0xA3, _rest::binary>>), do: true + def webm?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mov video. @@ -46,16 +46,16 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.mov") - iex> Infer.Video.is_mov(binary) + iex> Infer.Video.mov?(binary) true """ - @spec is_mov(binary()) :: boolean() - def is_mov(<<0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, _rest::binary>>), do: true - def is_mov(<<_data::binary-size(4), 0x6D, 0x6F, 0x6F, 0x76, _rest::binary>>), do: true - def is_mov(<<_data::binary-size(4), 0x6D, 0x64, 0x61, 0x74, _rest::binary>>), do: true - def is_mov(<<_data::binary-size(12), 0x6D, 0x64, 0x61, 0x74, _rest::binary>>), do: true - def is_mov(_binary), do: false + @spec mov?(binary()) :: boolean() + def mov?(<<0x0, 0x0, 0x0, 0x14, 0x66, 0x74, 0x79, 0x70, _rest::binary>>), do: true + def mov?(<<_data::binary-size(4), 0x6D, 0x6F, 0x6F, 0x76, _rest::binary>>), do: true + def mov?(<<_data::binary-size(4), 0x6D, 0x64, 0x61, 0x74, _rest::binary>>), do: true + def mov?(<<_data::binary-size(12), 0x6D, 0x64, 0x61, 0x74, _rest::binary>>), do: true + def mov?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a AVI video. @@ -63,20 +63,20 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.avi") - iex> Infer.Video.is_avi(binary) + iex> Infer.Video.avi?(binary) true """ - @spec is_avi(binary()) :: boolean() - def is_avi(<<0x52, 0x49, 0x46, 0x46, _data::binary-size(4), 0x41, 0x56, 0x49, _rest::binary>>), do: true - def is_avi(_binary), do: false + @spec avi?(binary()) :: boolean() + def avi?(<<0x52, 0x49, 0x46, 0x46, _data::binary-size(4), 0x41, 0x56, 0x49, _rest::binary>>), do: true + def avi?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a wmv video. """ - @spec is_wmv(binary()) :: boolean() - def is_wmv(<<0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, _rest::binary>>), do: true - def is_wmv(_binary), do: false + @spec wmv?(binary()) :: boolean() + def wmv?(<<0x30, 0x26, 0xB2, 0x75, 0x8E, 0x66, 0xCF, 0x11, 0xA6, 0xD9, _rest::binary>>), do: true + def wmv?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mpeg video. @@ -85,20 +85,20 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.mpeg") - iex> Infer.Video.is_mpeg(binary) + iex> Infer.Video.mpeg?(binary) true """ - @spec is_mpeg(binary()) :: boolean() - def is_mpeg(<<0x0, 0x0, 0x1, check_byte, _rest::binary>>) when check_byte >= 0xB0 and check_byte <= 0xBF, do: true - def is_mpeg(_binary), do: false + @spec mpeg?(binary()) :: boolean() + def mpeg?(<<0x0, 0x0, 0x1, check_byte, _rest::binary>>) when check_byte >= 0xB0 and check_byte <= 0xBF, do: true + def mpeg?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a flv video. """ - @spec is_flv(binary()) :: boolean() - def is_flv(<<0x46, 0x4C, 0x56, 0x01, _rest::binary>>), do: true - def is_flv(_binary), do: false + @spec flv?(binary()) :: boolean() + def flv?(<<0x46, 0x4C, 0x56, 0x01, _rest::binary>>), do: true + def flv?(_binary), do: false @doc """ Takes the binary file contents as arguments. Returns `true` if it's a mp4 video. @@ -106,38 +106,38 @@ defmodule Infer.Video do ## Examples iex> binary = File.read!("test/videos/sample.mp4") - iex> Infer.Video.is_mp4(binary) + iex> Infer.Video.mp4?(binary) true """ - @spec is_mp4(binary()) :: boolean() - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "r", "v", "c", "1", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "d", "a", "s", "h", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "2", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "3", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "4", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "5", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "6", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "m", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "m", "m", "p", "4", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "1", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "2", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "v", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "7", "1", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "M", "S", "N", "V", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "A", "S", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "C", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "S", "D", "C", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "H", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "M", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "P", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "S", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "C", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "H", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "M", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "P", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "S", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "F", "4", "V", " ", _rest::binary>>), do: true - def is_mp4(<<_data::binary-size(4), "f", "t", "y", "p", "F", "4", "P", " ", _rest::binary>>), do: true - def is_mp4(_binary), do: false + @spec mp4?(binary()) :: boolean() + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "r", "v", "c", "1", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "d", "a", "s", "h", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "2", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "3", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "4", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "5", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "6", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "i", "s", "o", "m", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "m", "m", "p", "4", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "1", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "2", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "4", "v", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "m", "p", "7", "1", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "M", "S", "N", "V", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "A", "S", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "C", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "S", "D", "C", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "H", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "M", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "P", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "S", "S", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "C", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "H", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "M", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "P", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "N", "D", "X", "S", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "F", "4", "V", " ", _rest::binary>>), do: true + def mp4?(<<_data::binary-size(4), "f", "t", "y", "p", "F", "4", "P", " ", _rest::binary>>), do: true + def mp4?(_binary), do: false end diff --git a/mix.exs b/mix.exs index 6d23480..02627c7 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Infer.MixProject do def project do [ app: :infer, - version: "0.1.1", + version: "0.2.0", elixir: "~> 1.10", start_permanent: Mix.env() == :prod, deps: deps(),