3 unstable releases

0.2.0 Jan 21, 2020
0.1.2 Jan 19, 2020
0.1.0 Jan 19, 2020

#231 in #lib

Download history 7/week @ 2024-07-20 31/week @ 2024-07-27 17/week @ 2024-08-03 12/week @ 2024-08-10 11/week @ 2024-08-17 11/week @ 2024-08-24 14/week @ 2024-08-31 15/week @ 2024-09-07 9/week @ 2024-09-14 29/week @ 2024-09-21 17/week @ 2024-09-28 7/week @ 2024-10-05 34/week @ 2024-10-12 8/week @ 2024-10-19 7/week @ 2024-10-26 21/week @ 2024-11-02

70 downloads per month
Used in 2 crates

MIT/Apache

19KB
118 lines

download_rs

使用rust写的一个简单 download 下载库

https://github.com/fengzhongyun1992/download_rs/actions https://github.com/fengzhongyun1992/download_rs/blob/master/LICENSE

简单使用

sync_download

  • cargo:
download_rs = {version="0.2.0",features=["sync_download"]}
  • code
use download_rs::sync_download::Download;
use std::error::Error;
use std::fs;

fn main() {
    let url = "https://www.baidu.com/img/bd_logo1.png";
    // 当前目录
     let filename = "bd_log1.png";
    // 指定 下载目录
    // let filename = "/download/";
    // 指定下载目录下载文件名,需要手动创建下载文件夹
    // let filename = "download/bd_log1.png";
    let download = Download::new(url,Some(filename),None);

    match download.download() {
        Ok(_) => println!("下载完成"),
        Err(e) => println!("下载出错 : {}",e.to_string()),
    }

    // 删除图片
    // fs::remove_file(filename).unwrap();
}

async_download

  • cargo:
download_rs = "0.2.0"

download_rs = {version="0.2.0",features=["async_download"]}
  • code
use download_rs::async_download::Download;
use std::fs;

fn main() {
    let url = "https://www.baidu.com/img/bd_logo1.png";
    // 当前目录
    let filename = "bd_log1.png";
    // 指定 下载目录
    // let filename = "/download/";
    // 指定下载目录下载文件名,需要手动创建下载文件夹
    // let filename = "download/bd_log1.png";
    let download = Download::new(url,Some(filename),None);

    match download.download() {
        Ok(_) => println!("下载完成"),
        Err(e) => println!("下载出错 : {}",e.to_string()),
    }

    // 删除图片
    // fs::remove_file(filename).unwrap();
}

async_download_default

  • cargo:
download_rs = "0.2.0"

download_rs = {version="0.2.0",features=["async_download"]}
  • code
use download_rs::async_download::Download;
use std::fs;

#[tokio::main]
async fn main() {
    let url = "https://www.baidu.com/img/bd_logo1.png";
    // 当前目录
    let filename = "bd_log1.png";

    // cargo test sync_download_test
//    let url = "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
//    let proxy = Some("http://127.0.0.1:7890");
//    let filename  = "sync_bd_logo1.png";

    // 指定 下载目录
    // let filename = "/download/";
    // 指定下载目录下载文件名,需要手动创建下载文件夹
    // let filename = "download/bd_log1.png";
    let download = Download::new(url,Some(filename),None);
//    let download = Download::new(url,Some(filename),proxy);
    match download.download_async().await {
        Err(e) => panic!("error: {}",e.to_string()),
        Ok(()) => println!("ok")
    }
    // 删除图片
    // fs::remove_file(filename).unwrap();
}

版本说明

0.2.0

  • 使用 new方法创建 Download对象
  • 添加 proxy 字段
  • 和 0.1.0 不兼容 🤭🤭🤭🤭

Dependencies

~4–16MB
~203K SLoC