morpheus_network::transfer::streaming

Struct StreamReader

Source
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: StreamConfig

Configuration.

§state: StreamState

Current state.

§buffer: Vec<u8>

Accumulated data.

§bytes_received: usize

Total bytes received.

§expected_size: Option<usize>

Expected total size (from Content-Length).

§bytes_since_progress: usize

Bytes since last progress callback.

§progress_callback: Option<ProgressCallback>

Progress callback (stored as Option since fn pointers can’t be Debug).

§cancelled: bool

Cancellation flag.

Implementations§

Source§

impl StreamReader

Source

pub fn new() -> Self

Create a new stream reader with default config.

Source

pub fn with_buffer_size(buffer_size: usize) -> Self

Create with specific buffer size.

Source

pub fn with_config(config: StreamConfig) -> Self

Create with full configuration.

Source

pub fn set_expected_size(&mut self, size: Option<usize>)

Set expected total size (from Content-Length header).

Source

pub fn expected_size(&self) -> Option<usize>

Get expected total size.

Source

pub fn set_progress_callback(&mut self, callback: ProgressCallback)

Set progress callback.

Source

pub fn state(&self) -> StreamState

Get current state.

Source

pub fn is_complete(&self) -> bool

Check if transfer is complete.

Source

pub fn is_cancelled(&self) -> bool

Check if transfer was cancelled.

Source

pub fn bytes_received(&self) -> usize

Get bytes received so far.

Source

pub fn progress_percent(&self) -> Option<u8>

Get progress as percentage (0-100).

Source

pub fn cancel(&mut self)

Cancel the transfer.

Source

pub fn feed(&mut self, data: &[u8]) -> Result<usize>

Feed data chunk to the reader.

Returns number of bytes consumed.

Source

pub fn finish(&mut self)

Mark transfer as complete (for chunked encoding without Content-Length).

Source

pub fn fail(&mut self)

Mark transfer as failed.

Source

pub fn data(&self) -> &[u8]

Get accumulated data.

Source

pub fn take_data(self) -> Vec<u8>

Take ownership of accumulated data.

Source

pub fn clear_buffer(&mut self)

Clear buffer but keep state.

Source

pub fn reset(&mut self)

Reset reader for reuse.

Source

fn report_progress(&self)

Report progress via callback.

Trait Implementations§

Source§

impl Debug for StreamReader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for StreamReader

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.