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Β§
- Cache
Inner π - Digest
Cache π - 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.
- Digest
File π - Digest
Record π - What one fileβs last verification saw.
- Hashing
Writer π - Feeds bytes into the digest and checkpoints cancellation every
intervalbytes, so a cancel during verification does not wait out the whole hash. - Progress
Writer π - 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Β§
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
Breakinto 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.
Nonewhen the file cannot be statβed, which leaves the caller to report whatever is wrong with it. - verify π
- Check
pathagainst the spec, hashing only what there is a digest for.
Type AliasesΒ§
- Reporter π
- The callerβs progress callback as the internals pass it around.