{"id":15010154,"url":"https://github.com/daskycodes/infer","last_synced_at":"2025-07-19T10:04:50.268Z","repository":{"id":43257671,"uuid":"441809309","full_name":"daskycodes/infer","owner":"daskycodes","description":"Infer file and MIME type by checking the magic number signature","archived":false,"fork":false,"pushed_at":"2024-04-09T10:07:03.000Z","size":80238,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-01T03:06:51.556Z","etag":null,"topics":["elixir","filetype","magic-number","mime"],"latest_commit_sha":null,"homepage":"https://hexdocs.pm/infer/readme.html","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/daskycodes.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-12-26T04:32:06.000Z","updated_at":"2025-04-09T10:20:08.000Z","dependencies_parsed_at":"2024-04-09T11:00:21.491Z","dependency_job_id":null,"html_url":"https://github.com/daskycodes/infer","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/daskycodes/infer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daskycodes%2Finfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daskycodes%2Finfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daskycodes%2Finfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daskycodes%2Finfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daskycodes","download_url":"https://codeload.github.com/daskycodes/infer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daskycodes%2Finfer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265915127,"owners_count":23848491,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir","filetype","magic-number","mime"],"created_at":"2024-09-24T19:30:58.493Z","updated_at":"2025-07-19T10:04:50.245Z","avatar_url":"https://github.com/daskycodes.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Infer\n\nA dependency free library to infer file and MIME type by checking the [magic number](\u003chttps://en.wikipedia.org/wiki/Magic_number_(programming)\u003e) signature.\n\nAn elixir adaption of the [`infer`](https://github.com/bojand/infer) rust library.\n\n## Installation\n\nThe package can be installed\nby adding `infer` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:infer, \"~\u003e 0.2.6\"}\n  ]\nend\n```\n\nThe docs can\nbe found at [https://hexdocs.pm/infer](https://hexdocs.pm/infer).\n\n## Examples\n\n### `Infer.get/1`\n\nTakes the binary file contents as argument and returns the `Infer.Type.t()` if the file matches one of the supported types. Returns `nil` otherwise.\n\n```elixir\niex\u003e binary = File.read!(\"test/images/sample.png\")\niex\u003e Infer.get(binary)\n%Infer.Type{extension: \"png\", matcher: \u0026Infer.Image.png?/1, matcher_type: :image, mime_type: \"image/png\"}\n```\n\n### `Infer.get_from_path/1`\n\nSimilar to `Infer.get/1`, but takes the file path as argument.\n\n```elixir\niex\u003e Infer.get_from_path(\"test/images/sample.png\")\n%Infer.Type{extension: \"png\", matcher: \u0026Infer.Image.png?/1, matcher_type: :image, mime_type: \"image/png\"}\n```\n\n### `Infer.is?/2`\n\nTakes the binary content and the file extension as arguments. Returns whether the file content is\nof the given extension.\n\n```elixir\niex\u003e binary = File.read!(\"test/images/sample.png\")\niex\u003e Infer.is?(binary, \"png\")\ntrue\n```\n\n### `Infer.mime?/2`\n\nTakes the binary content and the file extension as arguments. Returns whether the file content is\nof the given mime type.\n\n```elixir\niex\u003e binary = File.read!(\"test/images/sample.png\")\niex\u003e Infer.mime?(binary, \"image/png\")\ntrue\n```\n\n### `Infer.image?/1`\n\nTakes the binary file contents as argument and returns whether the file is an image or not.\n\n```elixir\niex\u003e binary = File.read!(\"test/images/sample.png\")\niex\u003e Infer.image?(binary)\ntrue\n```\n\n### `Infer.document?/1`\n\nTakes the binary file contents as argument and returns whether the file is a document (microsoft office, open office)\n\n```elixir\niex\u003e binary = File.read!(\"test/docs/sample.xlsx\")\niex\u003e Infer.document?(binary)\ntrue\n```\n\n### `Infer.Doc.docx?/1`\n\nTakes the binary file contents as arguments. Returns `true` if it's Microsoft Word Open XML Format Document (DOCX) data.\n\n```elixir\niex\u003e binary = File.read!(\"test/docs/sample.docx\")\niex\u003e Infer.Doc.docx?(binary)\ntrue\n```\n\n## Supported Types\n\n### Image\n\n| MIME                      | Extension |\n| ------------------------- | --------- |\n| image/jpeg                | jpg       |\n| image/jp2                 | jp2       |\n| image/png                 | png       |\n| image/gif                 | image/web |\n| image/x-canon-c32         | cr2       |\n| image/tiff                | tif       |\n| image/bmp                 | bmp       |\n| image/vnd.ms-photo        | jxr       |\n| image/vnd.adobe.photoshop | psd       |\n| image/vnd.microsoft.icon  | ico       |\n| image/heif                | heif      |\n| image/avif                | avif      |\n\n### Video\n\n| MIME             | Extension |\n| ---------------- | --------- |\n| video/mp4        | mp4       |\n| video/x-m4v      | m4v       |\n| video/x-matroska | mkv       |\n| video/webm       | webm      |\n| video/quicktime  | mov       |\n| video/x-msvideo  | avi       |\n| video/x-ms-wmv   | wmv       |\n| video/mpeg       | mpg       |\n| video/x-flv      | flv       |\n\n### Audio\n\n| MIME         | Extension |\n| ------------ | --------- |\n| audio/midi   | midi      |\n| audio/mpeg   | mp3       |\n| audio/m4a    | m4a       |\n| audio/ogg    | ogg       |\n| audio/x-flac | flac      |\n| audio/x-wav  | wav       |\n| audio/amr    | amr       |\n| audio/aac    | aac       |\n| audio/x-aiff | aiff      |\n\n### Document\n\n| MIME                                                                      | Extension |\n| ------------------------------------------------------------------------- | --------- |\n| application/msword                                                        | doc       |\n| application/vnd.openxmlformats-officedocument.wordprocessingml.document   | docx      |\n| application/vnd.ms-excel                                                  | xls       |\n| application/vnd.openxmlformats-officedocument.spreadsheetml.sheet         | xlsx      |\n| application/vnd.ms-powerpoint                                             | ppt       |\n| application/vnd.openxmlformats-officedocument.presentationml.presentation | pptx      |\n| application/vnd.oasis.opendocument.text                                   | odt       |\n| application/vnd.oasis.opendocument.spreadsheet                            | ods       |\n| application/vnd.oasis.opendocument.presentation                           | odp       |\n\n## Archive\n\n| MIME                                  | Extension |\n| ------------------------------------- | --------- |\n| application/epub+zip                  | epub      |\n| application/zip                       | zip       |\n| application/x-tar                     | tar       |\n| application/vnd.rar                   | rar       |\n| application/gzip                      | gz        |\n| application/x-bzip2                   | bz2       |\n| application/x-7z-compressed           | 7z        |\n| application/x-xz                      | xz        |\n| application/is_pdf                    | pdf       |\n| application/x-shockwave-flash         | swf       |\n| application/rtf                       | rtf       |\n| application/octet-stream              | eot       |\n| application/postscript                | ps        |\n| application/vnd.sqlite3               | sqlite    |\n| application/x-nintendo-nes-rom        | nex       |\n| application/x-unix-archive            | ar        |\n| application/x-compressed              | Z         |\n| application/x-lzip                    | lz        |\n| application/x-rpm                     | rpm       |\n| application/dicom                     | dcm       |\n| application/zstd                      | zst       |\n| application/x-ole-storage             | msi       |\n| application/x-google-chrome-extension | crx       |\n| application/vnd.ms-cab-compressed     | cab       |\n| application/vnd.debian.binary-package | deb       |\n\n### Font\n\n| MIME                   | Extension |\n| ---------------------- | --------- |\n| application/font-woff  | woff      |\n| application/font-woff2 | woff2     |\n| application/font-sfnt  | ttf       |\n| application/font-sfnt  | otf       |\n\n### Book\n\n| MIME                           | Extension |\n| ------------------------------ | --------- |\n| application/epub+zip           | epub      |\n| application/x-mobipocket-ebook | mobi      |\n\n### Application\n\n| MIME                                          | Extension |\n| --------------------------------------------- | --------- |\n| application/wasm                              | wasm      |\n| application/x-executable                      | elf       |\n| application/vnd.microsoft.portable-executable | exe       |\n| application/vnd.microsoft.portable-executable | dll       |\n| application/java                              | class     |\n| application/x-llvm                            | bc        |\n| application/x-mach-binary                     | mach      |\n| application/vnd.android.dex                   | dex       |\n| application/vnd.android.det                   | dey       |\n| application/x-x509-ca-cert                    | der       |\n| application/x-executable                      | obj       |\n\n## License\n\nThis project and is licensed under the MIT License - see the [LICENSE](https://github.com/daskycodes/infer/blob/main/LICENSE) file for details.\n\nCopyright (c) 2021 Daniel Khaapamyaki\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaskycodes%2Finfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaskycodes%2Finfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaskycodes%2Finfer/lists"}