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>
impl<'a, D: BlockDevice> FileReader<'a, D>
Sourcepub fn new(
device: &'a D,
fs_type: FsType,
header_block: u32,
) -> Result<Self, AffsError>
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 fromfs_type- Filesystem type (OFS or FFS)header_block- Block number of the file header
Sourcepub fn from_entry(
device: &'a D,
fs_type: FsType,
header_block: u32,
entry: &EntryBlock,
) -> Result<Self, AffsError>
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 fromfs_type- Filesystem type (OFS or FFS)header_block- Block number of the file headerentry- Already-parsed entry block
Sourcepub const fn header_block(&self) -> u32
pub const fn header_block(&self) -> u32
Get the block number of the file header.
Sourcepub fn reset(&mut self)
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.
Sourcepub fn read(&mut self, out: &mut [u8]) -> Result<usize, AffsError>
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.
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more