pub struct MagicDb { /* private fields */ }Expand description
Represents a database of MagicRule
Implementations§
Source§impl MagicDb
impl MagicDb
Sourcepub fn optimal_lazy_cache<R: Read + Seek>(f: R) -> Result<LazyCache<R>, Error>
pub fn optimal_lazy_cache<R: Read + Seek>(f: R) -> Result<LazyCache<R>, Error>
Prepares an LazyCache configured with optimal parameters for
read operations done during file identification
Sourcepub fn load(&mut self, mf: MagicSource) -> Result<&mut Self, Error>
pub fn load(&mut self, mf: MagicSource) -> Result<&mut Self, Error>
Loads rules from a MagicSource
§Arguments
mf- TheMagicSourceto load rules from
§Returns
Result<&mut Self, Error>- Self for chaining or an error
Sourcepub fn first_magic<R: Read + Seek>(
&self,
r: &mut R,
extension: Option<&str>,
) -> Result<Magic<'_>, Error>
pub fn first_magic<R: Read + Seek>( &self, r: &mut R, extension: Option<&str>, ) -> Result<Magic<'_>, Error>
Detects file Magic stopping at the first matching magic. Magic
rules are evaluated from the best to the least relevant, so this method
returns most of the time the best magic. For the rare cases where
it doesn’t or if the best result is always required, use MagicDb::best_magic
§Arguments
r- A readable and seekable inputextension- Optional file extension to use for acceleration
§Returns
Result<Magic<'_>, Error>- The detection result or an error
Sourcepub fn first_magic_with_lazy_cache<R: Read + Seek>(
&self,
cache: &mut LazyCache<R>,
extension: Option<&str>,
) -> Result<Magic<'_>, Error>
pub fn first_magic_with_lazy_cache<R: Read + Seek>( &self, cache: &mut LazyCache<R>, extension: Option<&str>, ) -> Result<Magic<'_>, Error>
An alternative to Self::first_magic using a LazyCache
to detects file Magic stopping at the first matching magic. Magic
rules are evaluated from the best to the least relevant, so this method
returns most of the time the best magic. For the rare cases where
it doesn’t or if the best result is always required, use MagicDb::best_magic
§Arguments
cache- ALazyCacheused for read operationsextension- Optional file extension to use for acceleration
§Returns
Result<Magic<'_>, Error>- The detection result or an error
§Notes
- Use this method only if you need to re-use a
LazyCachefor future read operations. - Use
Self::optimal_lazy_cacheto prepare an optimalLazyCache
Sourcepub fn all_magics_with_lazy_cache<R: Read + Seek>(
&self,
cache: &mut LazyCache<R>,
) -> Result<Vec<Magic<'_>>, Error>
pub fn all_magics_with_lazy_cache<R: Read + Seek>( &self, cache: &mut LazyCache<R>, ) -> Result<Vec<Magic<'_>>, Error>
An alternative to Self::all_magics using a LazyCache
to detects all Magic matching a given content.
§Arguments
r- A readable and seekable input
§Returns
Result<Vec<Magic<'_>>, Error>- All detection results sorted by strength or an error
§Notes
- Use this method only if you need to re-use a
LazyCachefor future read operations. - Use
Self::optimal_lazy_cacheto prepare an optimalLazyCache
Sourcepub fn best_magic_with_lazy_cache<R: Read + Seek>(
&self,
cache: &mut LazyCache<R>,
) -> Result<Magic<'_>, Error>
pub fn best_magic_with_lazy_cache<R: Read + Seek>( &self, cache: &mut LazyCache<R>, ) -> Result<Magic<'_>, Error>
An alternative to Self::best_magic using a LazyCache
to detect the best Magic matching a given content.
§Arguments
r- A readable and seekable input
§Returns
Result<Magic<'_>, Error>- The best detection result or an error
§Notes
- Use this method only if you need to re-use a
LazyCachefor future read operations. - Use
Self::optimal_lazy_cacheto prepare an optimalLazyCache