pub struct DownloadStream { /* private fields */ }Expand description
A streaming download handle that yields data chunks as they are reconstructed.
Created by FileReconstructor::reconstruct_to_stream. The reconstruction
task is spawned immediately but pauses until start is
called (or the first next / blocking_next).
Because the tokio::spawn happens at construction time, subsequent calls to
start(), next(), and blocking_next() do not require a tokio runtime
context.
Data is delivered by pulling items directly from the sequential writer’s
internal queue, bypassing the synchronous writer thread entirely. Each call
to blocking_next / next returns the
next sequential chunk, or None when the download is complete. Any
reconstruction error is surfaced on the call that would have returned the
next chunk (or on the final None boundary) via the shared run state.
Implementations§
Source§impl DownloadStream
impl DownloadStream
Sourcepub fn start(&mut self)
pub fn start(&mut self)
Unblocks the reconstruction task so it begins producing data.
If already started, this is a no-op. Called automatically on the first
next / blocking_next.
This method is non-async and does not require a tokio runtime context.
Sourcepub fn blocking_next(&mut self) -> Result<Option<Bytes>>
pub fn blocking_next(&mut self) -> Result<Option<Bytes>>
Returns the next chunk of downloaded data, blocking the current thread until data is available.
Returns Ok(None) when the download is complete.
§Panics
Panics if called from within an async runtime context (e.g. inside a
tokio::spawn or async fn). Use from a regular thread or from
tokio::task::spawn_blocking instead. For the async-safe variant,
use next.
Sourcepub async fn next(&mut self) -> Result<Option<Bytes>>
pub async fn next(&mut self) -> Result<Option<Bytes>>
Returns the next chunk of downloaded data asynchronously.
Returns Ok(None) when the download is complete or cancelled.
Sourcepub fn cancel(&mut self)
pub fn cancel(&mut self)
Cancels the in-progress (or not-yet-started) download.
Signals the shared run state so the reconstruction loop aborts at its
next check point or select! branch, and closes the channel receiver.
After calling this, subsequent calls to blocking_next
/ next will return Ok(None).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for DownloadStream
impl RefUnwindSafe for DownloadStream
impl Send for DownloadStream
impl Sync for DownloadStream
impl Unpin for DownloadStream
impl UnsafeUnpin for DownloadStream
impl UnwindSafe for DownloadStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> DropFlavorWrapper<T> for T
impl<T> DropFlavorWrapper<T> for T
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more