pub struct FileReader { /* private fields */ }
Expand description
File reading utility.
Can be used for both asynchronous and synchronous reads, as long as they’re read in the same order they were queued up.
Implementations§
Source§impl FileReader
impl FileReader
Sourcepub fn new(
arena: &'static LinearAllocator<'_>,
file: FileHandle,
staging_buffer_size: usize,
queue_capacity: usize,
) -> Option<FileReader>
pub fn new( arena: &'static LinearAllocator<'_>, file: FileHandle, staging_buffer_size: usize, queue_capacity: usize, ) -> Option<FileReader>
Creates a new FileReader
for reading file
, with a maximum of
queue_capacity
concurrent read operations.
Sourcepub fn staging_buffer_size(&self) -> usize
pub fn staging_buffer_size(&self) -> usize
Returns the size of the staging buffer where file read operations write to, i.e. the size of the largest read supported by this file reader.
Sourcepub fn push_read(&mut self, first_byte: u64, size: usize) -> bool
pub fn push_read(&mut self, first_byte: u64, size: usize) -> bool
Queues up a read operation starting at first_byte
, reading size
bytes. Returns true
if the request fit in the queue.
If size
is larger than FileReader::staging_buffer_size
, this will
always return false
.
Sourcepub fn dispatch_reads(&mut self, platform: &dyn Platform)
pub fn dispatch_reads(&mut self, platform: &dyn Platform)
Starts file read operations for the queued up loading requests.
Sourcepub fn pop_read<T, F>(
&mut self,
platform: &dyn Platform,
blocking: bool,
use_result: F,
) -> Result<T, FileReadError>
pub fn pop_read<T, F>( &mut self, platform: &dyn Platform, blocking: bool, use_result: F, ) -> Result<T, FileReadError>
Finishes the read operation at the front of the queue, and passes the results to the closure if the read was successful.
If blocking
is true
and FileReader::dispatch_reads
has not been
called, this will call it for convenience.