pub struct FetchConfigBuilder { /* private fields */ }Expand description
Builder for FetchConfig.
Implementations§
Source§impl FetchConfigBuilder
impl FetchConfigBuilder
Sourcepub fn revision(self, revision: &str) -> Self
pub fn revision(self, revision: &str) -> Self
Sets the git revision (branch, tag, or commit SHA) to download.
Defaults to "main" if not set.
Sourcepub fn token_from_env(self) -> Self
pub fn token_from_env(self) -> Self
Reads the authentication token from the HF_TOKEN environment variable.
Sourcepub fn filter(self, pattern: &str) -> Self
pub fn filter(self, pattern: &str) -> Self
Adds an include glob pattern. Only files matching at least one include pattern will be downloaded.
Can be called multiple times to add multiple patterns.
Sourcepub fn exclude(self, pattern: &str) -> Self
pub fn exclude(self, pattern: &str) -> Self
Adds an exclude glob pattern. Files matching any exclude pattern will be skipped, even if they match an include pattern.
Can be called multiple times to add multiple patterns.
Sourcepub fn concurrency(self, concurrency: usize) -> Self
pub fn concurrency(self, concurrency: usize) -> Self
Sets the number of files to download concurrently.
Defaults to 4.
Sourcepub fn output_dir(self, dir: PathBuf) -> Self
pub fn output_dir(self, dir: PathBuf) -> Self
Sets a custom output directory for downloaded files.
By default, files are stored in the standard HuggingFace cache directory
(~/.cache/huggingface/hub/). When set, the HuggingFace cache hierarchy
is created inside this directory instead.
Sourcepub fn timeout_per_file(self, duration: Duration) -> Self
pub fn timeout_per_file(self, duration: Duration) -> Self
Sets the maximum time allowed per file download.
If a single file download exceeds this duration, it is aborted and may be retried according to the retry policy.
Sourcepub fn timeout_total(self, duration: Duration) -> Self
pub fn timeout_total(self, duration: Duration) -> Self
Sets the maximum total time for the entire download operation.
If the total download time exceeds this duration, remaining files
are skipped and a FetchError::Timeout is returned.
Sourcepub fn max_retries(self, retries: u32) -> Self
pub fn max_retries(self, retries: u32) -> Self
Sets the maximum number of retry attempts per file.
Defaults to 3. Set to 0 to disable retries. Uses exponential backoff with jitter (base 300ms, cap 10s).
Sourcepub fn verify_checksums(self, verify: bool) -> Self
pub fn verify_checksums(self, verify: bool) -> Self
Enables or disables SHA256 checksum verification after download.
When enabled, downloaded files are verified against the SHA256 hash
from HuggingFace LFS metadata. Files without LFS metadata (small
config files stored directly in git) are skipped.
Defaults to true.
Sourcepub fn chunk_threshold(self, bytes: u64) -> Self
pub fn chunk_threshold(self, bytes: u64) -> Self
Sets the minimum file size (in bytes) for chunked parallel download.
Files at or above this threshold are downloaded using multiple HTTP
Range connections in parallel. Files below use the standard single
connection. Defaults to 100 MiB (104_857_600 bytes). Set to
u64::MAX to disable chunked downloads entirely.
Sourcepub fn connections_per_file(self, connections: usize) -> Self
pub fn connections_per_file(self, connections: usize) -> Self
Sets the number of parallel HTTP connections per large file.
Only applies to files at or above chunk_threshold. Defaults to 8.
Sourcepub fn on_progress<F>(self, callback: F) -> Self
pub fn on_progress<F>(self, callback: F) -> Self
Sets a progress callback invoked for each progress event.