#download #downloader #siwi #file-downloader #file-download

bin+lib siwi-download

Downloaders with a pure http implementation support breakpoint continuations

10 unstable releases (3 breaking)

Uses new Rust 2024

0.4.1 Feb 27, 2025
0.3.1 Jan 13, 2025
0.2.5 Nov 4, 2024
0.2.4 Dec 30, 2023
0.1.0 Feb 18, 2021

#331 in Filesystem

Download history 9/week @ 2024-12-05 10/week @ 2024-12-12 257/week @ 2025-01-09 19/week @ 2025-01-16 18/week @ 2025-02-13 2/week @ 2025-02-20 157/week @ 2025-02-27

159 downloads per month

MIT license

20KB
422 lines

Siwi Download

Download file

Siwi Download is a downloader build on tokio and reqwest.

Install

cargo install siwi-download

Download file

siwi-download https://nodejs.org/dist/v22.11.0/node-v22.11.0.pkg

Example

cargo run --example download

use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
use siwi_download::{
  download::{Download, DownloadOptions},
  error::AnyResult,
};
use tracing::Level;
use tracing_subscriber::FmtSubscriber;

#[tokio::main]
async fn main() -> AnyResult<()> {
  let subscriber = FmtSubscriber::builder()
    .with_max_level(Level::INFO)
    .finish();
  tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed");
  let url = "https://nodejs.org/dist/v22.11.0/node-v22.11.0.pkg";
  let mut storage_path = std::env::current_dir()?;
  storage_path.push("storage");
  let storage_path = storage_path.to_str().unwrap();
  let mut options = DownloadOptions::default();
  let mut headers = HeaderMap::new();
  headers.insert(USER_AGENT, HeaderValue::from_str("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36")?);
  options
    .set_headers(headers)
    .set_file_name("node-v22.11.0.pkg")
    .set_show_progress(true);

  let download = Download::new(storage_path);
  download.auto_create_storage_path().await?;

  let report = download.download(url, options).await?;
  println!("report {:#?}", report);
  Ok(())
}
  • Write a CLI tool
use siwi_download::download::Download;
use siwi_download::download::DownloadOptions;
use siwi_download::error::AnyResult;
#[tokio::main]
async fn main() -> AnyResult<()> {
  let args: Vec<String> = std::env::args().collect();
  let storage_path = std::env::current_dir()?;
  let storage_path = storage_path.to_str().unwrap_or("");

  if let Some(url) = args.get(1) {
    let mut options = DownloadOptions::default();
    options.set_show_progress(true);
    let download = Download::new(storage_path);
    let report = download.download(url, options).await?;
    println!("{:?}", report);
  }
  Ok(())
}

Dependencies

~11–23MB
~315K SLoC