#download #url #link #wrote #couldn-t

bin+lib traxex

A library to download files through url link

2 releases

0.1.1 Jan 19, 2024
0.1.0 Aug 5, 2019

#2 in #wrote

37 downloads per month

MIT license

220KB
227 lines

Traxex

LICENSE Crates.io Version Crates.io Coverage Status

Linux: Build Status Windows: Build status

Introduction

Traxex is the name of a Dota hero my wife like most, so I chose this as the name. When I try to download some files in another rust application, which I am working on. I couldn't find a easy to use library for downloading like wget or something similar. Therefore, I wrote this library, a very easy download library. As I am a newbee in rust, so there may be some code can be improved. Welcome to give me some advice by issues or pull request. Thank you in advance.

Usage

There are a binary which can be used to download files through url and a library to be used in your code.

Binary Usage

USAGE:
    traxex.exe [OPTIONS] <url>

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -o, --output <output>    Specify the local output filename or directory

ARGS:
    <url>

Library Usage

There is only one public method to use download. This method has two params, the first is a &str url link, and the second is the output folder or output filename Option<&str>. If you don't want to give the filename, you can just leave the second parameter as None. It will generate a given filename according to the url path or from Content-Disposition headers if present. This method can return a Result<String>, which is the filename of the downloaded file.

extern crate lib_traxex;
use lib_traxex::download::download;

fn main() {
    let url_str = "https://raw.githubusercontent.com/zhangzhishan/blogpics/dev/traxex.jpg";

    match download(url_str, None) {
        Err(why) => panic!("couldn't write to : {}", why.to_string()),
        Ok(display) => println!("successfully wrote to {}", display)
    }
}

Reference

Python wget

Dependencies

~22–35MB
~610K SLoC