pub struct Settings<S> { /* private fields */ }
Expand description
Settings to configure the stream behavior.
Implementations§
Source§impl<S> Settings<S>
impl<S> Settings<S>
Sourcepub fn prefetch_bytes(self, prefetch_bytes: u64) -> Self
pub fn prefetch_bytes(self, prefetch_bytes: u64) -> Self
How many bytes to download from the stream before allowing read requests. This is used to create a buffer between the read position and the stream position and prevent stuttering.
The default value is 256 kilobytes.
Sourcepub fn batch_write_size(self, batch_write_size: NonZeroUsize) -> Self
pub fn batch_write_size(self, batch_write_size: NonZeroUsize) -> Self
The maximum number of bytes written to the underlying
StorageWriter
before yielding to the async runtime. This
prevents large writes from performing long blocking operations without giving the scheduler
a chance to schedule other tasks.
The default value is 4096.
Sourcepub fn retry_timeout(self, retry_timeout: Duration) -> Self
pub fn retry_timeout(self, retry_timeout: Duration) -> Self
If there is no new data for a duration greater than this timeout, we will attempt to reconnect to the server.
This timeout is designed to help streams recover during temporary network failures, but you may need to increase this if you’re seeing warnings about timeouts in the logs under normal network conditions.
The default value is 5 seconds.
Sourcepub fn cancel_on_drop(self, cancel_on_drop: bool) -> Self
pub fn cancel_on_drop(self, cancel_on_drop: bool) -> Self
If set to true
, this will cause the stream download task to automatically cancel when the
StreamDownload
instance is dropped. It’s useful to disable this
if you want to ensure the stream shuts down cleanly.
The default value is true
.
Sourcepub fn on_progress<F>(self, f: F) -> Self
pub fn on_progress<F>(self, f: F) -> Self
Attach a callback function that will be called when a new chunk of the stream is processed.
The provided CancellationToken
can be used to immediately cancel the stream.
§Example
use reqwest::Client;
use stream_download::Settings;
use stream_download::http::HttpStream;
use stream_download::source::SourceStream;
let settings = Settings::default();
settings.on_progress(|stream: &HttpStream<Client>, state, _| {
let progress = state.current_position as f32 / stream.content_length().unwrap() as f32;
println!("progress: {}%", progress * 100.0);
});
Sourcepub fn on_reconnect<F>(self, f: F) -> Self
pub fn on_reconnect<F>(self, f: F) -> Self
Attach a callback function that will be called when the stream reconnects after a failure.
The provided CancellationToken
can be used to immediately cancel the stream.
Sourcepub const fn get_prefetch_bytes(&self) -> u64
pub const fn get_prefetch_bytes(&self) -> u64
Retrieves the configured prefetch bytes
Sourcepub const fn get_write_batch_size(&self) -> usize
pub const fn get_write_batch_size(&self) -> usize
Retrieves the configured batch write size
Source§impl Settings<HttpStream<ClientWithMiddleware>>
impl Settings<HttpStream<ClientWithMiddleware>>
Sourcepub fn add_default_middleware<M>(middleware: M)where
M: Middleware,
Available on crate feature reqwest-middleware
only.
pub fn add_default_middleware<M>(middleware: M)where
M: Middleware,
reqwest-middleware
only.Adds a new reqwest_middleware::Middleware