pub struct StreamReader {
config: StreamConfig,
state: StreamState,
buffer: Vec<u8>,
bytes_received: usize,
expected_size: Option<usize>,
bytes_since_progress: usize,
progress_callback: Option<ProgressCallback>,
cancelled: bool,
}Expand description
Streaming data reader with progress tracking.
Accumulates data chunks and provides progress updates.
Fields§
§config: StreamConfigConfiguration.
state: StreamStateCurrent state.
buffer: Vec<u8>Accumulated data.
bytes_received: usizeTotal bytes received.
expected_size: Option<usize>Expected total size (from Content-Length).
bytes_since_progress: usizeBytes since last progress callback.
progress_callback: Option<ProgressCallback>Progress callback (stored as Option since fn pointers can’t be Debug).
cancelled: boolCancellation flag.
Implementations§
Source§impl StreamReader
impl StreamReader
Sourcepub fn with_buffer_size(buffer_size: usize) -> Self
pub fn with_buffer_size(buffer_size: usize) -> Self
Create with specific buffer size.
Sourcepub fn with_config(config: StreamConfig) -> Self
pub fn with_config(config: StreamConfig) -> Self
Create with full configuration.
Sourcepub fn set_expected_size(&mut self, size: Option<usize>)
pub fn set_expected_size(&mut self, size: Option<usize>)
Set expected total size (from Content-Length header).
Sourcepub fn expected_size(&self) -> Option<usize>
pub fn expected_size(&self) -> Option<usize>
Get expected total size.
Sourcepub fn set_progress_callback(&mut self, callback: ProgressCallback)
pub fn set_progress_callback(&mut self, callback: ProgressCallback)
Set progress callback.
Sourcepub fn state(&self) -> StreamState
pub fn state(&self) -> StreamState
Get current state.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Check if transfer is complete.
Sourcepub fn is_cancelled(&self) -> bool
pub fn is_cancelled(&self) -> bool
Check if transfer was cancelled.
Sourcepub fn bytes_received(&self) -> usize
pub fn bytes_received(&self) -> usize
Get bytes received so far.
Sourcepub fn progress_percent(&self) -> Option<u8>
pub fn progress_percent(&self) -> Option<u8>
Get progress as percentage (0-100).
Sourcepub fn feed(&mut self, data: &[u8]) -> Result<usize>
pub fn feed(&mut self, data: &[u8]) -> Result<usize>
Feed data chunk to the reader.
Returns number of bytes consumed.
Sourcepub fn finish(&mut self)
pub fn finish(&mut self)
Mark transfer as complete (for chunked encoding without Content-Length).
Sourcepub fn clear_buffer(&mut self)
pub fn clear_buffer(&mut self)
Clear buffer but keep state.
Sourcefn report_progress(&self)
fn report_progress(&self)
Report progress via callback.