Skip to main content

Module fetch

Module fetch 

Source
Expand description

Model fetch: download, resume, and verify before use.

Re-exportsΒ§

use std::collections::HashMap; πŸ”’
use std::fs; πŸ”’
use std::fs::File; πŸ”’
use std::ops::ControlFlow; πŸ”’
use std::path::Path; πŸ”’
use std::path::PathBuf; πŸ”’
use std::sync::mpsc; πŸ”’
use std::sync::Mutex; πŸ”’
use std::sync::PoisonError; πŸ”’
use sha2::Digest; πŸ”’
use sha2::Sha256; πŸ”’
use crate::Config; πŸ”’
use crate::Error; πŸ”’
use crate::ModelSpec; πŸ”’

StructsΒ§

CacheInner πŸ”’
DigestCache πŸ”’
Remembers which digest each model file had when it was last verified, so a file that has not changed since is not read end to end again.
DigestFile πŸ”’
DigestRecord πŸ”’
What one file’s last verification saw.
HashingWriter πŸ”’
Feeds bytes into the digest and checkpoints cancellation every interval bytes, so a cancel during verification does not wait out the whole hash.
ProgressWriter πŸ”’
Counts bytes on their way to disk and forwards the running total, rate-limited so a multi-gigabyte transfer does not call back once per read.
Report πŸ”’
One model thread’s progress event and the channel its verdict comes back on.

EnumsΒ§

Progress
What prepare reports as it works.

ConstantsΒ§

DIGEST_CACHE_FILE πŸ”’
The record of verified digests inside Config::digest_cache_dir.
DIGEST_CACHE_VERSION πŸ”’
The record’s own version. A file written by a layout this build does not know is ignored rather than misread.
PROGRESS_INTERVAL πŸ”’
Bytes between progress reports during a transfer.
VERIFY_PROGRESS_INTERVAL πŸ”’
Bytes between cancellation checkpoints while hashing. Coarse, since a checkpoint round-trips the prepare driver: at hashing speed this keeps cancel latency near 120 ms without an event per read.

FunctionsΒ§

announce πŸ”’
Hand one progress event to the caller, turning a Break into the error that unwinds the whole operation.
check_present πŸ”’
Check a model already on disk, verifying it unless its record says it has not changed since the last check.
content_range_starts_at πŸ”’
Parse Content-Range: bytes <start>-<end>/<total> and say whether the body starts where the caller asked. A missing or unreadable header counts as no, which costs a restart rather than a splice.
discard_unusable_partial πŸ”’
Decide what a failed partial deserves, and say so in the log.
download πŸ”’
ensure πŸ”’
is_bytes_verdict πŸ”’
Whether a failure is a verdict on the BYTES rather than on reaching or reading them. Only a verdict on the bytes is a download’s to settle: an io error says nothing about them, and a fetch cannot answer it.
models_dir πŸ”’
The configured directory, else a subdirectory of the platform cache directory. Never derived from the working directory: a caller with no usable cache directory gets an error to act on.
prepare
Make every model the config names present and verified.
sha256 πŸ”’
state_of πŸ”’
The state a record is keyed on: length and modification time. None when the file cannot be stat’ed, which leaves the caller to report whatever is wrong with it.
verify πŸ”’
Check path against the spec, hashing only what there is a digest for.

Type AliasesΒ§

Reporter πŸ”’
The caller’s progress callback as the internals pass it around.