FileReader

Struct FileReader 

Source
pub struct FileReader<'a, D: BlockDevice> { /* private fields */ }
Expand description

Streaming file reader.

Reads file data sequentially with zero heap allocation. Supports both OFS and FFS filesystems.

§Example

let mut reader = FileReader::new(&device, FsType::Ffs, file_header_block)?;
let mut buf = [0u8; 1024];
loop {
    let n = reader.read(&mut buf)?;
    if n == 0 {
        break; // EOF
    }
    // Process buf[..n]
}

Implementations§

Source§

impl<'a, D: BlockDevice> FileReader<'a, D>

Source

pub fn new( device: &'a D, fs_type: FsType, header_block: u32, ) -> Result<Self, AffsError>

Create a new file reader from a file header block.

§Arguments
  • device - Block device to read from
  • fs_type - Filesystem type (OFS or FFS)
  • header_block - Block number of the file header
Source

pub fn from_entry( device: &'a D, fs_type: FsType, header_block: u32, entry: &EntryBlock, ) -> Result<Self, AffsError>

Create a file reader from an already-parsed entry block.

This avoids re-reading the header block if you already have it.

§Arguments
  • device - Block device to read from
  • fs_type - Filesystem type (OFS or FFS)
  • header_block - Block number of the file header
  • entry - Already-parsed entry block
Source

pub const fn size(&self) -> u32

Get the total file size in bytes.

Source

pub const fn header_block(&self) -> u32

Get the block number of the file header.

Source

pub const fn remaining(&self) -> u32

Get the number of bytes remaining to read.

Source

pub const fn is_eof(&self) -> bool

Check if we’ve reached end of file.

Source

pub const fn position(&self) -> u32

Get current position in the file.

Source

pub fn reset(&mut self)

Reset the reader to the beginning of the file.

This restores all internal state to allow reading from the start.

Source

pub fn read(&mut self, out: &mut [u8]) -> Result<usize, AffsError>

Read data into a buffer.

Returns the number of bytes read. Returns 0 at end of file.

Source

pub fn read_all(&mut self, out: &mut [u8]) -> Result<usize, AffsError>

Read the entire file into a buffer.

The buffer must be at least as large as the file size. Returns the number of bytes read.

Source

pub fn seek(&mut self, position: u32) -> Result<(), AffsError>

Seek to a specific position in the file.

Note: Seeking backwards resets to the beginning and seeks forward, which may need to re-read extension blocks for large files.

Auto Trait Implementations§

§

impl<'a, D> Freeze for FileReader<'a, D>

§

impl<'a, D> RefUnwindSafe for FileReader<'a, D>
where D: RefUnwindSafe,

§

impl<'a, D> Send for FileReader<'a, D>
where D: Sync,

§

impl<'a, D> Sync for FileReader<'a, D>
where D: Sync,

§

impl<'a, D> Unpin for FileReader<'a, D>

§

impl<'a, D> UnwindSafe for FileReader<'a, D>
where D: RefUnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.