-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
525 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
target | ||
Cargo.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[package] | ||
name = "ml-downloader" | ||
version = "0.1.0" | ||
license = "MIT" | ||
description = "Simple blocking downloader based on reqwest" | ||
repository = "https://github.com/malaire/ml-downloader" | ||
keywords = [ "client", "download", "http", "https", "request" ] | ||
categories = [ "web-programming::http-client" ] | ||
edition = "2021" | ||
|
||
include = [ | ||
"/src", | ||
"LICENSE", | ||
"README.md", | ||
"build.rs", | ||
] | ||
|
||
[dependencies] | ||
bytes = "1.1.0" | ||
digest = "0.10.3" | ||
fastrand = "1.7.0" | ||
hex = "0.4.3" | ||
reqwest = { version = "0.11.9", features = [ "blocking" ] } | ||
|
||
[dev-dependencies] | ||
# used in `RequestBuilder::hash` example | ||
sha2 = "0.10.2" | ||
|
||
[build-dependencies] | ||
readme-rustdocifier = "0.1.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
## ml-downloader | ||
|
||
Simple blocking downloader, featuring: | ||
|
||
- retries with custom delays | ||
- custom interval between successful downloads for rate limiting | ||
- hash check (optional) | ||
- based on [reqwest](https://crates.io/crates/reqwest) | ||
|
||
## Examples | ||
|
||
### Simple usage | ||
|
||
Create [`Downloader`] with default configuration and then download one file. | ||
|
||
```no_run | ||
use ml_downloader::Downloader; | ||
let mut downloader = Downloader::new()?; | ||
let bytes = downloader.get("https://example.com/").send()?; | ||
# Ok::<(), ml_downloader::Error>(()) | ||
``` | ||
|
||
### Custom configuration | ||
|
||
Create [`Downloader`] with | ||
- `"foobar/1.0"` as `USER_AGENT` | ||
- `1.0 - 1.1` seconds interval between successful downloads | ||
- two retries after failed download | ||
- `2.0 - 2.2` seconds delay after initial failure | ||
- `5.0 - 5.5` seconds delay after 2nd failure | ||
|
||
```rust | ||
use ml_downloader::Downloader; | ||
|
||
let mut downloader = Downloader::builder() | ||
.reqwest(|cb| cb.user_agent("foobar/1.0")) | ||
.interval(1.0, 1.1) | ||
.retry_delays(&[(2.0, 2.2), (5.0, 5.5)]) | ||
.build()?; | ||
|
||
# Ok::<(), ml_downloader::Error>(()) | ||
``` | ||
|
||
[`Downloader`]: https://docs.rs/ml-downloader/0.1.0/ml_downloader/struct.Downloader.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use std::{env, error::Error, fs, path::PathBuf}; | ||
|
||
const CRATE_NAME: &str = "ml_downloader"; | ||
|
||
fn main() -> Result<(), Box<dyn Error>> { | ||
println!("cargo:rerun-if-changed=README.md"); | ||
fs::write( | ||
PathBuf::from(env::var("OUT_DIR")?).join("README-rustdocified.md"), | ||
readme_rustdocifier::rustdocify( | ||
&fs::read_to_string("README.md")?, | ||
&env::var("CARGO_PKG_NAME")?, | ||
Some(&env::var("CARGO_PKG_VERSION")?), | ||
Some(CRATE_NAME), | ||
)?, | ||
)?; | ||
Ok(()) | ||
} |
Oops, something went wrong.