pub enum IdentifyMethod {
Magic(&'static [u8]),
MultipleMagic(&'static [&'static [u8]]),
Extension(&'static str),
Extensions(&'static [&'static str]),
Name(&'static str),
Names(&'static [&'static str]),
}Expand description
Fast, declarative way to identify a content type without running custom code.
A ContentIdentifier can return one of these variants from
identify_method so the
scanner can build efficient matchers (tries, magic tables, etc.)
once and reuse them for every scanned object.
If none of the variants fit your identifier, return None from
identify_method and perform your own check inside
validate.
Magic patterns (Magic,
MultipleMagic) must be at most 16 bytes.
The scanner only feeds the matcher the first 16 bytes of content,
and only when at least one identifier registered such a pattern;
ScannerBuilder::build panics if a
registered magic is longer. To match bytes past that window, return
None from identify_method and call Content::read in
validate.
Variants§
Magic(&'static [u8])
Content whose first bytes exactly match this magic sequence.
The sequence must be at most 16 bytes. Longer patterns can never
match (the scanner reads only content.read(0, 16)) and cause
ScannerBuilder::build to panic.
That 16-byte read is performed only when at least one identifier
registered a Magic or
MultipleMagic pattern.
MultipleMagic(&'static [&'static [u8]])
Content whose first bytes match any of these magic sequences.
Each sequence must be at most 16 bytes; see Magic.
Extension(&'static str)
Content whose file extension matches this string (ASCII case-insensitive, without the leading dot).
Notes.TXT matches Extension("txt"); a registered pattern
"JPG" matches photo.jpg.
Extensions(&'static [&'static str])
Content whose file extension matches any of these strings (ASCII case-insensitive, without the leading dot).
Name(&'static str)
Content whose file name (basename) matches this string (ASCII case-insensitive).
makefile and MAKEFILE both match Name("Makefile").
Names(&'static [&'static str])
Content whose file name (basename) matches any of these strings (ASCII case-insensitive).