{"id":13587082,"url":"https://github.com/bojand/infer","last_synced_at":"2025-05-14T06:12:46.189Z","repository":{"id":34222330,"uuid":"172104710","full_name":"bojand/infer","owner":"bojand","description":"Small crate to infer file and MIME type by checking the magic number signature ","archived":false,"fork":false,"pushed_at":"2025-02-02T01:24:26.000Z","size":18962,"stargazers_count":332,"open_issues_count":25,"forks_count":33,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-02T23:18:03.717Z","etag":null,"topics":["filetype","hacktoberfest","magic-number","mime"],"latest_commit_sha":null,"homepage":"","language":"Rust","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/bojand.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2019-02-22T17:13:46.000Z","updated_at":"2025-04-02T13:08:25.000Z","dependencies_parsed_at":"2024-06-18T17:41:35.431Z","dependency_job_id":"ae177425-1cad-4185-a4d6-3e26eb4240ef","html_url":"https://github.com/bojand/infer","commit_stats":{"total_commits":162,"total_committers":21,"mean_commits":7.714285714285714,"dds":"0.49382716049382713","last_synced_commit":"66c1890f7f44f24d3dfa6c4eb966b84942ab9ece"},"previous_names":[],"tags_count":33,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bojand%2Finfer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bojand%2Finfer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bojand%2Finfer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bojand%2Finfer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bojand","download_url":"https://codeload.github.com/bojand/infer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248313652,"owners_count":21082892,"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":["filetype","hacktoberfest","magic-number","mime"],"created_at":"2024-08-01T15:06:00.577Z","updated_at":"2025-04-10T23:25:11.694Z","avatar_url":"https://github.com/bojand.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# infer\n\n![Build Status](https://github.com/bojand/infer/workflows/build/badge.svg)\n[![crates version](https://img.shields.io/crates/v/infer.svg)](https://crates.io/crates/infer)\n[![documentation](https://docs.rs/infer/badge.svg)](https://docs.rs/infer)\n\nSmall crate to infer file and MIME type by checking the\n[magic number](https://en.wikipedia.org/wiki/Magic_number_(programming)) signature.\n\nAdaptation of [filetype](https://github.com/h2non/filetype) Go package ported to Rust.\n\nDoes not require magic file database (i.e. `/etc/magic`).\n\n## Features\n\n- Supports a [wide range](#supported-types) of file types\n- Provides file extension and MIME type\n- File discovery by extension or MIME type\n- File discovery by class (image, video, audio...)\n- Supports custom new types and matchers\n\n## Installation\n\nThis crate works with Cargo and is on [crates.io](https://crates.io/crates/infer).\nAdd it to your `Cargo.toml` like so:\n\n```toml\n[dependencies]\ninfer = \"0.3\"\n```\n\nIf you are not using the custom matcher or the file type from file path functionality you\ncan make this crate even lighter by importing it with no default features, like so:\n\n```toml\n[dependencies]\ninfer = { version = \"0.3\", default-features = false }\n```\n\n## no_std and no_alloc support\n\nThis crate supports `no_std` and `no_alloc` environments. `std` support is enabled by default,\nbut you can disable it by importing the crate with no default features, making it depend\nonly on the Rust `core` Library.\n\n`alloc` has to be enabled to be able to use custom file matchers.\n\n`std` has to be enabled to be able to get the file type from a file given the file path.\n\n## Examples\n\nMost operations can be done via _top level functions_, but they are also available through the `Infer`\nstruct, which must be used when dealing custom matchers.\n\n### Get the type of a buffer\n\n```rust\nlet buf = [0xFF, 0xD8, 0xFF, 0xAA];\nlet kind = infer::get(\u0026buf).expect(\"file type is known\");\n\nassert_eq!(kind.mime_type(), \"image/jpeg\");\nassert_eq!(kind.extension(), \"jpg\");\n```\n\n### Check file type by path\n\n```rust\nlet kind = infer::get_from_path(\"testdata/sample.jpg\")\n    .expect(\"file read successfully\")\n    .expect(\"file type is known\");\n\nassert_eq!(kind.mime_type(), \"image/jpeg\");\nassert_eq!(kind.extension(), \"jpg\");\n```\n\n### Check for specific type\n\n```rust\nlet buf = [0xFF, 0xD8, 0xFF, 0xAA];\nassert!(infer::image::is_jpeg(\u0026buf));\n```\n\n### Check for specific type class\n\n```rust\nlet buf = [0xFF, 0xD8, 0xFF, 0xAA];\nassert!(infer::is_image(\u0026buf));\n```\n\n### Adds a custom file type matcher\n\n```rust\nfn custom_matcher(buf: \u0026[u8]) -\u003e bool {\n    return buf.len() \u003e= 3 \u0026\u0026 buf[0] == 0x10 \u0026\u0026 buf[1] == 0x11 \u0026\u0026 buf[2] == 0x12;\n}\n\nlet mut info = infer::Infer::new();\ninfo.add(\"custom/foo\", \"foo\", custom_matcher);\n\nlet buf = [0x10, 0x11, 0x12, 0x13];\nlet kind = info.get(\u0026buf).expect(\"file type is known\");\n\nassert_eq!(kind.mime_type(), \"custom/foo\");\nassert_eq!(kind.extension(), \"foo\");\n```\n\n## Supported types\n\n#### Image\n\n- **jpg** - `image/jpeg`\n- **png** - `image/png`\n- **gif** - `image/gif`\n- **webp** - `image/webp`\n- **cr2** - `image/x-canon-cr2`\n- **tif** - `image/tiff`\n- **bmp** - `image/bmp`\n- **heif** - `image/heif`\n- **avif** - `image/avif`\n- **jxr** - `image/vnd.ms-photo`\n- **psd** - `image/vnd.adobe.photoshop`\n- **ico** - `image/vnd.microsoft.icon`\n- **ora** - `image/openraster`\n- **djvu** - `image/vnd.djvu`\n\n#### Video\n\n- **mp4** - `video/mp4`\n- **m4v** - `video/x-m4v`\n- **mkv** - `video/x-matroska`\n- **webm** - `video/webm`\n- **mov** - `video/quicktime`\n- **avi** - `video/x-msvideo`\n- **wmv** - `video/x-ms-wmv`\n- **mpg** - `video/mpeg`\n- **flv** - `video/x-flv`\n\n#### Audio\n\n- **mid** - `audio/midi`\n- **mp3** - `audio/mpeg`\n- **m4a** - `audio/m4a`\n- **ogg** - `audio/ogg`\n- **flac** - `audio/x-flac`\n- **wav** - `audio/x-wav`\n- **amr** - `audio/amr`\n- **aac** - `audio/aac`\n- **aiff** - `audio/x-aiff`\n- **dsf** - `audio/x-dsf`\n- **ape** - `audio/x-ape`\n\n#### Archive\n\n- **epub** - `application/epub+zip`\n- **zip** - `application/zip`\n- **tar** - `application/x-tar`\n- **rar** - `application/vnd.rar`\n- **gz** - `application/gzip`\n- **bz2** - `application/x-bzip2`\n- **bz3** - `application/vnd.bzip3`\n- **7z** - `application/x-7z-compressed`\n- **xz** - `application/x-xz`\n- **pdf** - `application/pdf`\n- **swf** - `application/x-shockwave-flash`\n- **rtf** - `application/rtf`\n- **eot** - `application/octet-stream`\n- **ps** - `application/postscript`\n- **sqlite** - `application/vnd.sqlite3`\n- **nes** - `application/x-nintendo-nes-rom`\n- **crx** - `application/x-google-chrome-extension`\n- **cab** - `application/vnd.ms-cab-compressed`\n- **deb** - `application/vnd.debian.binary-package`\n- **ar** - `application/x-unix-archive`\n- **Z** - `application/x-compress`\n- **lz** - `application/x-lzip`\n- **rpm** - `application/x-rpm`\n- **dcm** - `application/dicom`\n- **zst** - `application/zstd`\n- **lz4** - `application/x-lz4`\n- **msi** - `application/x-ole-storage`\n- **cpio** - `application/x-cpio`\n- **par2** - `application/x-par2`\n\n#### Book\n\n- **epub** - `application/epub+zip`\n- **mobi** - `application/x-mobipocket-ebook`\n\n#### Documents\n\n- **doc** - `application/msword`\n- **docx** - `application/vnd.openxmlformats-officedocument.wordprocessingml.document`\n- **xls** - `application/vnd.ms-excel`\n- **xlsx** - `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`\n- **ppt** - `application/vnd.ms-powerpoint`\n- **pptx** - `application/vnd.openxmlformats-officedocument.presentationml.presentation`\n- **odt** - `application/vnd.oasis.opendocument.text`\n- **ods** - `application/vnd.oasis.opendocument.spreadsheet`\n- **odp** - `application/vnd.oasis.opendocument.presentation`\n\n#### Font\n\n- **woff** - `application/font-woff`\n- **woff2** - `application/font-woff`\n- **ttf** - `application/font-sfnt`\n- **otf** - `application/font-sfnt`\n\n#### Application\n\n- **wasm** - `application/wasm`\n- **exe** - `application/vnd.microsoft.portable-executable`\n- **dll** - `application/vnd.microsoft.portable-executable`\n- **elf** - `application/x-executable`\n- **bc** - `application/llvm`\n- **mach** - `application/x-mach-binary`\n- **class** - `application/java`\n- **dex** - `application/vnd.android.dex`\n- **dey** - `application/vnd.android.dey`\n- **der** - `application/x-x509-ca-cert`\n- **obj** - `application/x-executable`\n- **qcow2** - `application/x-qemu-disk`\n\n## Known Issues\n\n- `exe` and `dll` have the same magic number so it's not possible to tell which one just based on the binary data. `exe` is returned for all.\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbojand%2Finfer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbojand%2Finfer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbojand%2Finfer/lists"}