pub struct DownloadBuilder { /* private fields */ }Expand description
Fluent builder for a single download.
Create one via crate::builder() or DownloadBuilder::new().
Implementations§
Source§impl DownloadBuilder
impl DownloadBuilder
Sourcepub fn output(self, path: impl Into<String>) -> Self
pub fn output(self, path: impl Into<String>) -> Self
Set the output file path or directory.
If a directory is given, the filename is inferred from the URL.
Sourcepub fn connections(self, n: usize) -> Self
pub fn connections(self, n: usize) -> Self
Number of parallel HTTP connections. Clamped to 1–32.
Sourcepub fn speed_limit(self, bytes_per_sec: u64) -> Self
pub fn speed_limit(self, bytes_per_sec: u64) -> Self
Global speed limit in bytes per second.
Sourcepub fn proxy(self, url: impl Into<String>) -> Self
pub fn proxy(self, url: impl Into<String>) -> Self
HTTP proxy URL (e.g. "http://proxy:8080" or "socks5://host:1080").
Sourcepub fn proxy_auth(
self,
user: impl Into<String>,
pass: impl Into<String>,
) -> Self
pub fn proxy_auth( self, user: impl Into<String>, pass: impl Into<String>, ) -> Self
Proxy credentials (optional, required only for authenticated proxies).
Sourcepub fn sha256(self, hash: impl Into<String>) -> Self
pub fn sha256(self, hash: impl Into<String>) -> Self
Expect a SHA-256 digest. The download fails if the file doesn’t match.
Sourcepub fn verify_from(self, url: impl Into<String>) -> Self
pub fn verify_from(self, url: impl Into<String>) -> Self
Download a checksum sidecar file from url and use it to populate the
expected digest automatically.
Supports GNU (<hash> <file>) and BSD (SHA256 (<file>) = <hash>) formats.
Sourcepub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn header(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a custom HTTP request header. Can be called multiple times.
Sourcepub fn retry(self, config: RetryConfig) -> Self
pub fn retry(self, config: RetryConfig) -> Self
Override the default retry policy.
Sourcepub fn range(self, start: u64, end: u64) -> Self
pub fn range(self, start: u64, end: u64) -> Self
Request only a byte range of the file: [start, end] (both inclusive).
Sends Range: bytes=start-end. The returned DownloadResult will have
bytes_downloaded equal to end - start + 1.
Sourcepub fn download(self) -> Result<DownloadResult, KgetError>
pub fn download(self) -> Result<DownloadResult, KgetError>
Execute the download synchronously and return metrics on success.
Sourcepub fn download_to_bytes(self) -> Result<Vec<u8>, KgetError>
pub fn download_to_bytes(self) -> Result<Vec<u8>, KgetError>
Download entirely into memory and return the raw bytes.
Respects .range(), .proxy(), and .header() settings.
Does not write to disk, so .output() is ignored.
Sourcepub fn download_to_reader(self) -> Result<impl Read, KgetError>
pub fn download_to_reader(self) -> Result<impl Read, KgetError>
Download to memory and return an impl Read.
Convenience wrapper over download_to_bytes.
Sourcepub fn spawn(
self,
) -> (JoinHandle<Result<DownloadResult, KgetError>>, Receiver<DownloadEvent>)
pub fn spawn( self, ) -> (JoinHandle<Result<DownloadResult, KgetError>>, Receiver<DownloadEvent>)
Spawn the download in a background thread and return an event channel.
The DownloadEvent receiver yields progress updates until the channel
is closed (on completion or error). Call .join() on the handle to
retrieve the final DownloadResult.
Auto Trait Implementations§
impl Freeze for DownloadBuilder
impl RefUnwindSafe for DownloadBuilder
impl Send for DownloadBuilder
impl Sync for DownloadBuilder
impl Unpin for DownloadBuilder
impl UnsafeUnpin for DownloadBuilder
impl UnwindSafe for DownloadBuilder
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> 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