pub struct ProgressReader<'a, R> { /* private fields */ }Expand description
Wrapper reader that tracks bytes read and reports progress.
This reader wraps any Read implementation and reports bytes read
to a progress callback. To reduce callback overhead, it uses batching
with a configurable threshold (default: 1 MB).
§Batching Behavior
The reader accumulates bytes read and only invokes the progress callback when:
- The accumulated bytes reach the batch threshold (default: 1 MB)
- The reader is dropped (flushes remaining bytes)
This reduces callback overhead for large files while still providing responsive progress updates.
§Examples
use exarch_core::ProgressCallback;
use exarch_core::creation::progress::ProgressReader;
use std::fs::File;
use std::io::Read;
use std::path::Path;
let file = File::open("large_file.bin")?;
let mut progress = DummyProgress;
let mut reader = ProgressReader::new(file, &mut progress);
let mut buffer = vec![0u8; 8192];
loop {
let bytes_read = reader.read(&mut buffer)?;
if bytes_read == 0 {
break;
}
// Progress is automatically reported
}Implementations§
Source§impl<'a, R> ProgressReader<'a, R>
impl<'a, R> ProgressReader<'a, R>
Sourcepub fn new(inner: R, progress: &'a mut dyn ProgressCallback) -> Self
pub fn new(inner: R, progress: &'a mut dyn ProgressCallback) -> Self
Creates a new progress-tracking reader with default batch threshold.
The default batch threshold is 1 MB (1,048,576 bytes).
§Parameters
inner: The reader to wrapprogress: Mutable reference to the progress callback
§Examples
use exarch_core::ProgressCallback;
use exarch_core::creation::progress::ProgressReader;
use std::fs::File;
use std::path::Path;
let file = File::open("data.bin")?;
let mut progress = DummyProgress;
let reader = ProgressReader::new(file, &mut progress);Sourcepub fn with_batch_threshold(
inner: R,
progress: &'a mut dyn ProgressCallback,
batch_threshold: u64,
) -> Self
pub fn with_batch_threshold( inner: R, progress: &'a mut dyn ProgressCallback, batch_threshold: u64, ) -> Self
Creates a new progress-tracking reader with custom batch threshold.
§Parameters
inner: The reader to wrapprogress: Mutable reference to the progress callbackbatch_threshold: Number of bytes to accumulate before reporting
§Examples
use exarch_core::ProgressCallback;
use exarch_core::creation::progress::ProgressReader;
use std::fs::File;
use std::path::Path;
let file = File::open("data.bin")?;
let mut progress = DummyProgress;
// Report progress every 64 KB
let reader = ProgressReader::with_batch_threshold(file, &mut progress, 64 * 1024);Sourcepub fn flush_progress(&mut self)
pub fn flush_progress(&mut self)
Flushes any accumulated bytes to the progress callback.
This is called automatically when the reader is dropped, but can be called manually if needed.
Trait Implementations§
Source§impl<R> Drop for ProgressReader<'_, R>
impl<R> Drop for ProgressReader<'_, R>
Source§impl<R: Read> Read for ProgressReader<'_, R>
impl<R: Read> Read for ProgressReader<'_, R>
Source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
1.36.0 · Source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read, except that it reads into a slice of buffers. Read moreSource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector)1.0.0 · Source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf. Read more1.0.0 · Source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf. Read more1.6.0 · Source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf. Read moreSource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)Source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf)cursor. Read more1.0.0 · Source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read. Read more