Download System

Overview

The download system provides async file downloads with SHA1 verification, retry logic, and proper error handling.

Quick Example

use lighty_core::download_file;

#[tokio::main]
async fn main()  {
    // Download with SHA1 verification
    let path = download_file(
        "https://example.com/file.zip",
        "/tmp/file.zip",
        Some("expected-sha1-hash")
    ).await?;

    println!("Downloaded to: {:?}", path);
    Ok(())
}

Flow Diagram

spinner

API Reference

download_file(url, destination, expected_sha1)

Downloads a file from a URL to the specified destination.

Parameters:

  • url: &str - URL to download from

  • destination: impl AsRef<Path> - Local file path

  • expected_sha1: Option<&str> - Optional SHA1 hash for verification

Returns: Result<PathBuf, DownloadError>

Features:

  • Automatic retry on network errors

  • Parent directory creation

  • SHA1 verification

  • Async streaming for memory efficiency

Error Handling

Example:

Best Practices

1. Always Verify Critical Files

2. Handle Retries Gracefully

3. Use Absolute Paths

Advanced Usage

Concurrent Downloads

Progress Tracking

Currently not directly supported. Use the indicatif crate wrapper:

See Also

Last updated