download_url_to_temp_file

Function download_url_to_temp_file 

Source
pub fn download_url_to_temp_file<FStart, FProgress, FChunk>(
    client: &Client,
    url: &str,
    temp_path: &Path,
    label: impl Display,
    on_start: FStart,
    on_progress: FProgress,
    on_chunk: FChunk,
) -> Result<()>
where FStart: FnOnce(Option<u64>), FProgress: FnMut(u64), FChunk: FnMut(&[u8]) -> Result<(), BoxError>,
Expand description

Streams url into temp_path.

on_start receives the server-reported content length when available. on_progress receives byte deltas since the previous progress callback, which matches the existing inc(...)-style callers in the UI layer. on_chunk sees each raw chunk before it is written to disk. If the server reports a content length, the helper verifies the streamed byte count matches it before committing the temp file. The temporary file is removed automatically if streaming or finalization fails.