pub struct SniffWindow<'a> { /* private fields */ }Expand description
A bounded window of bytes handed to a prober. Holds a prefix of the source
(the head) plus the absolute base offset that prefix starts at, so a prober
reads magic without an unbounded scan and without touching the source
directly. It also carries the source’s total_len and a tail window (the
last N bytes), so a prober can match a trailer signature — e.g. the DMG
koly footer at total_len - 512 — that the head window never reaches.
Implementations§
Source§impl<'a> SniffWindow<'a>
impl<'a> SniffWindow<'a>
Sourcepub fn new(base: u64, bytes: &'a [u8]) -> Self
pub fn new(base: u64, bytes: &'a [u8]) -> Self
A head-only window of bytes that begins at absolute base in the
source. total_len is inferred as base + bytes.len() and the tail is
empty — existing head-magic probers are unaffected.
Sourcepub fn with_tail(
base: u64,
bytes: &'a [u8],
total_len: u64,
tail: &'a [u8],
) -> Self
pub fn with_tail( base: u64, bytes: &'a [u8], total_len: u64, tail: &'a [u8], ) -> Self
A window carrying both a head (bytes at base) and a tail (the last
bytes of the source), plus the source’s total_len. tail must end at
total_len for the from-end probes to be correct.
Sourcepub fn at(&self, off: usize, n: usize) -> Option<&[u8]>
pub fn at(&self, off: usize, n: usize) -> Option<&[u8]>
The n bytes at window-relative off, or None if out of range. Never
panics — the panic-free way to test a magic.
Sourcepub fn has_magic(&self, off: usize, magic: &[u8]) -> bool
pub fn has_magic(&self, off: usize, magic: &[u8]) -> bool
True when the window has magic at window-relative off.
Sourcepub fn tail_at(&self, from_end: usize, n: usize) -> Option<&[u8]>
pub fn tail_at(&self, from_end: usize, n: usize) -> Option<&[u8]>
The n bytes of the tail beginning from_end bytes before the source’s
end, or None when the tail is too short. Never panics.
Sourcepub fn has_magic_from_end(&self, from_end: usize, magic: &[u8]) -> bool
pub fn has_magic_from_end(&self, from_end: usize, magic: &[u8]) -> bool
True when the tail carries magic starting from_end bytes before the
source’s end (e.g. has_magic_from_end(512, b"koly") for a DMG footer).
False if the tail is too short — the panic-free trailer probe.