pub struct FileReader<'a, DATA: Read + Seek> { /* private fields */ }Expand description
A reader for file content in a FAT filesystem.
This struct provides a Read implementation that follows the cluster chain
to read file contents.
§Buffering
When the alloc feature is enabled, the reader can optionally buffer data
to reduce the number of seek and read operations:
-
with_buffer: Enable cluster-level buffering. Each cluster is read entirely into memory and subsequent reads are served from the buffer. -
with_cached_chain: Pre-cache the entire cluster chain. This is useful for small files where you want to avoid repeated FAT lookups.
Implementations§
Source§impl<'a, DATA: Read + Seek> FileReader<'a, DATA>
impl<'a, DATA: Read + Seek> FileReader<'a, DATA>
Sourcepub fn new(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
pub fn new(fs: &'a FatVolume<DATA>, entry: &FileEntry) -> Result<Self>
Create a new FileReader for a file entry.
Returns an error if the entry is a directory.
Sourcepub fn with_buffer(self) -> Self
pub fn with_buffer(self) -> Self
Enable cluster-level buffering.
When enabled, each cluster is read entirely into memory on first access, and subsequent reads within that cluster are served from the buffer. This reduces the number of seek operations at the cost of memory usage.
Memory usage: One cluster size (typically 4KB to 64KB).
Sourcepub fn with_cached_chain(self) -> Result<Self>
pub fn with_cached_chain(self) -> Result<Self>
Pre-cache the entire cluster chain.
This reads the entire FAT chain for the file into memory, eliminating the need for FAT lookups during sequential reads. This is most beneficial for fragmented files or when performing many random seeks.
Memory usage: 4 bytes per cluster in the file.
Sourcepub fn read(&mut self, buf: &mut [u8]) -> Result<usize>
pub fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Read data from the file.
Reads up to buf.len() bytes, or fewer at end-of-file. Use a small buf to
stream incrementally; a larger buf allows more bytes per call (including
contiguous-cluster bulk I/O when the chain is cached). The underlying
Read / Seek implementation can enforce
alignment or transfer sizes as needed. Optional per-cluster buffering applies when
enabled.
Sourcepub fn read_to_vec(&mut self) -> Result<Vec<u8>>
pub fn read_to_vec(&mut self) -> Result<Vec<u8>>
Read all bytes from the current read position through the end of the file.
Data is read starting at this reader’s current offset in the file (the same
position the next read would use—not necessarily offset 0). Bytes
already consumed by earlier read or read_to_vec calls are not read
again. The allocation size is remaining; bytes are read using the
same internal bulk-read path as read.