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, ms: MagicSource) -> &mut Self
pub fn load(&mut self, ms: MagicSource) -> &mut Self
Sourcepub fn load_bulk<I: Iterator<Item = MagicSource>>(&mut self, it: I) -> &mut Self
pub fn load_bulk<I: Iterator<Item = MagicSource>>(&mut self, it: I) -> &mut Self
Loads multiple MagicSource items efficiently in bulk.
This is more efficient than loading each individually. After processing all sources, it applies finalization step only once.
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
§Warning
File extension acceleration is made to evaluate rules faster by testing
first the rules defining this extension with an !:ext entry.
Whether you use extension acceleration or not with this function should not
produce different results. Yet this makes the assumption rules are written
correctly and every rule concerned defines !:ext when it is appropriate.
If some rules are missing it, results might differ.
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
§Warning
File extension acceleration is made to evaluate rules faster by testing
first the rules defining this extension with an !:ext entry.
Whether you use extension acceleration or not with this function should not
produce different results. Yet this makes the assumption rules are written
correctly and every rule concerned defines !:ext when it is appropriate.
If some rules are missing it, results might differ.
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