Skip to main content

Reader

Struct Reader 

Source
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>

Source

pub const fn new(file: &'a [u8]) -> Self

A reader over the whole of file.

Source

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.

Source

pub const fn file(&self) -> &'a [u8] ⓘ

The complete file this reader was cut from.

Source

pub const fn position(&self) -> usize

The cursor’s absolute offset within the file.

Source

pub const fn remaining(&self) -> usize

Bytes between the cursor and the end of this reader’s window.

Source

pub const fn is_empty(&self) -> bool

Whether the cursor has reached the end of the window.

Source

pub fn rest(&self) -> &'a [u8] ⓘ

The window’s bytes from the cursor onward.

Source

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.

Source

pub fn skip(&mut self, len: usize) -> Result<()>

Advance the cursor by len bytes without returning them.

§Errors

As Reader::take.

Source

pub fn u8(&mut self) -> Result<u8>

Read one byte.

§Errors

As Reader::take.

Source

pub fn u16(&mut self) -> Result<u16>

Read a big-endian u16. ISOBMFF is big-endian throughout.

§Errors

As Reader::take.

Source

pub fn u32(&mut self) -> Result<u32>

Read a big-endian u32.

§Errors

As Reader::take.

Source

pub fn u64(&mut self) -> Result<u64>

Read a big-endian u64.

§Errors

As Reader::take.

Source

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.

Source

pub fn fourcc(&mut self) -> Result<FourCc>

Read a four-character code.

§Errors

As Reader::take.

Source

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.

Source

pub fn full_box(&mut self) -> Result<(u8, u32)>

Read the version and flags of a full box.

§Errors

As Reader::take.

Source

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.

Source

pub fn payload(&self, header: &BoxHeader) -> Reader<'a>

A reader over header’s payload.

Source

pub fn find(&mut self, kind: &[u8; 4]) -> Result<Option<Reader<'a>>>

Find the first child box of type kind, if any.

Scans from the cursor and leaves the cursor where it stopped, so this is for one-shot lookups rather than repeated probing of one container.

§Errors

As Reader::next_box.

Trait Implementations§

Source§

impl<'a> Clone for Reader<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Reader<'a>

Source§

impl<'a> Debug for Reader<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>

§

impl<'a> Sync for Reader<'a>

§

impl<'a> Unpin for Reader<'a>

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.