Skip to content

Commit

Permalink
first public version
Browse files Browse the repository at this point in the history
  • Loading branch information
malaire committed Feb 27, 2022
1 parent eaac975 commit ea1e84f
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
target
Cargo.lock
30 changes: 30 additions & 0 deletions Cargo.toml
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"
45 changes: 45 additions & 0 deletions README.md
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
17 changes: 17 additions & 0 deletions build.rs
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(())
}
Loading

0 comments on commit ea1e84f

Please sign in to comment.