Skip to content

robo9k/rust-magic

Repository files navigation

rust-magic maintenance status build status Rust safety dance crates.io version crates.io license docs.rs status REUSE status OpenSSF best practices OpenSSF scorecard Codecov

libmagic bindings for the Rust programming language.

libmagic recognizes the type of data contained in a file (or buffer) and can give you a textual description, a MIME type and the usual file extensions.

Usage

This project's crate is published on the crates.io Rust package registry: the magic crate

In your Rust project, use cargo add to specify dependencies:

$ cargo add magic

To install the latest in-development version instead:

$ cargo add --git https://github.com/robo9k/rust-magic

You might be familiar with libmagic's CLI; file:

$ file data/tests/rust-logo-128x128-blk.png
data/tests/rust-logo-128x128-blk.png: PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced

You can implement something similar in Rust with the magic crate, see crate README:

$ cargo run --example file-ish -- data/tests/rust-logo-128x128-blk.png
PNG image data, 128 x 128, 8-bit/color RGBA, non-interlaced

For more details, check the magic rustdoc: robo9k.github.io/rust-magic/magic

Requirements

For the magic crate requirements, see crate README.

For developing the rust-magic project, see CONTRIBUTING.

License

This project is licensed under either of

at your option.

For further details, see LICENSE.

Security

See SECURITY.

Contribution

See CONTRIBUTING.