pub struct Magic<'m> { /* private fields */ }Expand description
Represents a file magic detection result
Implementations§
Source§impl<'m> Magic<'m>
impl<'m> Magic<'m>
Sourcepub fn stream_kind(&self) -> Option<StreamKind>
pub fn stream_kind(&self) -> Option<StreamKind>
Gets the detected StreamKind describing the type of detected data,
or None if it was not determined.
§Returns
Option<StreamKind>- The detected kind orNone
Sourcepub fn into_owned<'owned>(self) -> Magic<'owned>
pub fn into_owned<'owned>(self) -> Magic<'owned>
Sourcepub fn message(&self) -> String
pub fn message(&self) -> String
Gets the formatted message describing the file type
§Returns
String- The formatted message
§Note
The returned string only ever contains printable ASCII (graphic
characters and spaces). Any other byte, including non-ASCII UTF-8
sequences, control characters and Unicode format/bidi characters, is
escaped as \NNN (octal), the same way libmagic does. This makes the
output safe to print directly to a terminal.
Sourcepub fn message_parts(&self) -> impl Iterator<Item = &str>
pub fn message_parts(&self) -> impl Iterator<Item = &str>
Returns an iterator over the individual raw parts of the magic message
A magic message is typically composed of multiple parts, each appended
during successful magic tests. This method provides an efficient way to
iterate over these parts without concatenating them into a new string,
as done when calling Magic::message.
§Returns
impl Iterator<Item = &str>- An iterator yielding string slices of each message part
§Note
Unlike Magic::message, the returned parts are not sanitized:
they may contain raw control characters (e.g. ESC) extracted from
the scanned data. Do not print them directly to a terminal, as this
could result in terminal escape sequence injection. This method is
intended for programmatic inspection only.
Sourcepub fn strength(&self) -> u64
pub fn strength(&self) -> u64
Gets the confidence score of the detection. This
value is used to sort Magic in MagicDb::best_magic
and MagicDb::all_magics.
§Returns
u64- The confidence score attributed to thatMagic