Skip to main content

ReadSeekExt

Trait ReadSeekExt 

Source
pub trait ReadSeekExt: Read + Seek {
    // Required methods
    fn peek_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize>;
    fn read_exact_or_eof_at(
        &mut self,
        offset: u64,
        buffer: &mut [u8],
    ) -> Result<usize>;
}
Expand description

Extension methods for values that implement both Read and Seek.

ReadSeekExt provides position-preserving read helpers for common inspection use cases such as file signature checks, MIME detection, and random-offset probing.

Required Methods§

Source

fn peek_exact_or_eof(&mut self, buffer: &mut [u8]) -> Result<usize>

Reads from the current position and restores the original position.

This method has the same partial-EOF semantics as crate::ReadExt::read_exact_or_eof, but it leaves the stream positioned where it was before the call when restoration succeeds.

§Parameters
  • buffer: Destination buffer to fill.
§Returns

The number of bytes written into buffer.

§Errors

Returns an error when reading the current position, reading bytes, or restoring the original position fails. If both reading and restoration fail, the restoration error is returned because the caller’s stream position contract was not preserved.

Source

fn read_exact_or_eof_at( &mut self, offset: u64, buffer: &mut [u8], ) -> Result<usize>

Reads from offset and restores the original position.

This method seeks to offset, reads until buffer is full or EOF is reached, and then restores the position that was current before the call.

§Parameters
  • offset: Absolute byte offset from the start of the stream.
  • buffer: Destination buffer to fill.
§Returns

The number of bytes written into buffer.

§Errors

Returns an error when reading the current position, seeking to offset, reading bytes, or restoring the original position fails. If restoration fails, the restoration error is returned.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T> ReadSeekExt for T
where T: Read + Seek + ?Sized,