pub struct Reader<'a> { /* private fields */ }Expand description
A checked cursor over a byte range of the file.
Holds the whole file buffer plus the window this reader is allowed to
touch, so a BoxHeader’s absolute offsets stay meaningful when a child
reader is handed to a nested parser.
Implementations§
Source§impl<'a> Reader<'a>
impl<'a> Reader<'a>
Sourcepub fn window(file: &'a [u8], start: usize, end: usize) -> Self
pub fn window(file: &'a [u8], start: usize, end: usize) -> Self
A reader over file[start..end], clamped to the file.
Used to resolve an iloc extent, which names an absolute range that a
hostile file may place outside the data it actually shipped.
Sourcepub const fn remaining(&self) -> usize
pub const fn remaining(&self) -> usize
Bytes between the cursor and the end of this reader’s window.
Sourcepub fn take(&mut self, len: usize) -> Result<&'a [u8]>
pub fn take(&mut self, len: usize) -> Result<&'a [u8]>
Take len bytes, advancing the cursor.
§Errors
Returns PixelsError::Malformed if the window holds fewer than len
bytes from the cursor.
Sourcepub fn uint(&mut self, size: u8) -> Result<u64>
pub fn uint(&mut self, size: u8) -> Result<u64>
Read a big-endian unsigned integer of size bytes, where size is 0,
4 or 8.
iloc encodes its offset and length field widths this way, and a width
of zero means the field is absent and reads as zero.
§Errors
Returns PixelsError::Malformed for a width the specification does
not allow, or as Reader::take.
Sourcepub fn cstring(&mut self) -> Result<&'a str>
pub fn cstring(&mut self) -> Result<&'a str>
Read a null-terminated UTF-8 string.
Used by infe for item names and by auxC for the auxiliary type URN.
An unterminated string consumes the rest of the box, which is what
real files with a missing terminator intend and costs nothing to allow.
§Errors
Returns PixelsError::Malformed if the bytes are not UTF-8.
Sourcepub fn next_box(&mut self) -> Option<Result<BoxHeader>>
pub fn next_box(&mut self) -> Option<Result<BoxHeader>>
Read the next box header, positioning the cursor at its payload.
Returns None at the end of the window. A trailing run shorter than a
header is treated as padding and ends iteration rather than failing:
real files pad, and refusing them buys no safety.
§Errors
Returns PixelsError::Malformed if a box declares a size smaller
than its own header — which would make iteration loop forever — or one
that runs past the end of the enclosing box.