{"id":24904614,"url":"https://github.com/robo9k/rust-magic","last_synced_at":"2025-04-12T18:51:07.346Z","repository":{"id":43210548,"uuid":"24536112","full_name":"robo9k/rust-magic","owner":"robo9k","description":"Rust high level bindings crate for the `libmagic` C library","archived":false,"fork":false,"pushed_at":"2025-02-06T01:25:46.000Z","size":332,"stargazers_count":53,"open_issues_count":25,"forks_count":16,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T23:08:55.209Z","etag":null,"topics":["file","libmagic","magic","rust"],"latest_commit_sha":null,"homepage":"https://robo9k.github.io/rust-magic/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robo9k.png","metadata":{"files":{"readme":"README-crate.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-09-27T16:00:53.000Z","updated_at":"2025-04-02T11:40:10.000Z","dependencies_parsed_at":"2023-10-15T14:32:32.272Z","dependency_job_id":"bcdc5244-8e95-493d-96f3-108a03c2e28f","html_url":"https://github.com/robo9k/rust-magic","commit_stats":{"total_commits":240,"total_committers":6,"mean_commits":40.0,"dds":0.4708333333333333,"last_synced_commit":"3e2d5c2664d27ab85e9ce8c0afc17fa0fe04f292"},"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robo9k%2Frust-magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robo9k%2Frust-magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robo9k%2Frust-magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robo9k%2Frust-magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robo9k","download_url":"https://codeload.github.com/robo9k/rust-magic/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618223,"owners_count":21134199,"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":["file","libmagic","magic","rust"],"created_at":"2025-02-01T23:26:54.756Z","updated_at":"2025-04-12T18:51:07.326Z","avatar_url":"https://github.com/robo9k.png","language":"Rust","readme":"\r\n[//]: # (This is the README for the `magic` crate only)\r\n\r\n[//]: # (The whole project has docs in https://github.com/robo9k/rust-magic )\r\n\r\nHigh-level bindings for `libmagic`\r\n\r\n# About\r\n\r\nThis crate provides bindings for the [`libmagic` C library]((https://www.darwinsys.com/file/)),\r\nwhich recognizes the type of data contained in a file (or buffer) and can give you\r\na textual description, a MIME type and the usual file extensions.\r\n\r\n# Usage\r\n\r\n```rust\r\n// only for Rust Edition 2018, see https://doc.rust-lang.org/edition-guide/rust-2021/prelude.html\r\nuse std::convert::TryInto;\r\n\r\nfn file_example() -\u003e Result\u003c(), Box\u003cdyn std::error::Error\u003e\u003e {\r\n    // Open a new configuration with flags\r\n    let cookie = magic::Cookie::open(magic::cookie::Flags::ERROR)?;\r\n\r\n    // Load a specific database\r\n    // (so exact test text assertion below works regardless of the system's default database version)\r\n    let database = [\"data/tests/db-images-png\"].try_into()?;\r\n    // You can instead load the default database\r\n    //let database = Default::default();\r\n\r\n    let cookie = cookie.load(\u0026database)?;\r\n\r\n    let file = \"data/tests/rust-logo-128x128-blk.png\";\r\n\r\n    // Analyze the file\r\n    assert_eq!(cookie.file(file)?, \"PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced\");\r\n\r\n    Ok(())\r\n}\r\n```\r\n\r\nCheck the [crate rustdoc](https://docs.rs/magic) for more details.\r\n\r\n# Repository\r\n\r\nThe project's repository is [github.com/robo9k/rust-magic](https://github.com/robo9k/rust-magic)\r\n\r\nIt contains the latest in-development version of the `magic` crate (might not be published to `crates.io` yet),  \r\nmore [examples](https://github.com/robo9k/rust-magic/tree/main/examples) how to use the `magic` crate  \r\nas well as [issues](https://github.com/robo9k/rust-magic/issues)\r\nand [discussions](https://github.com/robo9k/rust-magic/discussions).\r\n\r\n# MSRV\r\n\r\nThe Minimum Supported Rust Version (MSRV) is Rust 1.56 or higher.\r\n\r\nThis version might be changed in the future, but it will be done with a crate version bump.\r\n\r\n# Requirements\r\n\r\nBy default, compiling the `magic` crate will (via the [`magic-sys` crate](https://crates.io/crates/magic-sys))\r\nsearch your system library paths for a shared library version of `libmagic` to link against.  \r\nFor this to work, you need to install the development version of `libmagic` in a standard location:\r\n```shell\r\n$ # On Debian based Linux systems:\r\n$ sudo apt-get install libmagic1 libmagic-dev\r\n\r\n$ # On macOS:\r\n$ brew install libmagic\r\n\r\n$ # On Windows:\r\n$ cargo install cargo-vcpkg\r\n$ cargo vcpkg build\r\n```\r\n\r\nIf you're cross-compiling, or need more control over which library is selected,\r\nsee [how to build `magic-sys`](https://crates.io/crates/magic-sys#building).\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobo9k%2Frust-magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobo9k%2Frust-magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobo9k%2Frust-magic/lists"}