1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
//! mojique provides a simple interface into [libmagic][libmagic] (using [`magic_sys`] underneath),
//! along with an optional [`Send`], [`Sync`] pool that makes it easier to use libmagic in
//! multi-threaded and async environments.
//!
//! To use mojique, you need to:
//!
//! 1. Create a [`Config`], which is one of:
//! 1. [`DefaultConfig`]: uses the system magic database.
//! 1. [`BufferConfig`]: uses magic database(s) provided from `&[u8]` buffers.
//! 1. [`FileConfig`]: uses magic database(s) on the filesystem.
//! 1. Build either a single [`Handle`] (which is [`Send`], but not [`Sync`]), or a [`Pool`] of
//! handles (that is both [`Send`] and [`Sync`]), which can then be used to acquire handles via
//! [`Pool::handle`].
//! 1. Call methods on [`Handle`] to detect file types based on content.
//!
//! ## Simple example
//!
//! A simple example that uses the system magic database to get a MIME type:
//!
//! ```
//! use mojique::{Config, DefaultConfig, Flag};
//!
//! let mut handle = DefaultConfig::default().set_flag(Flag::Mime).build_handle()?;
//! let mime_type = handle.buffer(b"#include <stdio.h>")?;
//!
//! println!("MIME type of something looking like C is: {mime_type}");
//! # anyhow::Ok(())
//! ```
//!
//! ## Pools
//!
//! Building a pool uses the same configuration:
//!
//! ```
//! use mojique::{Config, DefaultConfig, Flag};
//!
//! let pool = DefaultConfig::default().set_flag(Flag::Mime).build_pool()?;
//! # anyhow::Ok(())
//! ```
//!
//! Once you have a pool, you can [`Clone`] it as much as needed and use [`Pool::handle`] to
//! acquire handles to specific tasks or threads.
//!
//! [libmagic]: https://www.darwinsys.com/file/
pub use magic_sys;
use c_int;
pub use crate::;
/// Returns the libmagic version.