Giter Club home page Giter Club logo

ml-downloader's Introduction

ml-downloader

Simple blocking downloader, featuring:

  • retries with custom delays
  • custom interval between successful downloads for rate limiting
  • hash check (optional)
  • based on reqwest

Examples

Simple usage

Create Downloader with default configuration and then download one file.

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
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>(())

ml-downloader's People

Contributors

malaire avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

dilawar

ml-downloader's Issues

Crash on unwrap()

Hi!
Thank you for your interesting crate!

I tried it with the updated code from hhtpmock example for a simple get json request :

example

    let m = server.mock(|when, then| {
        when.method(GET)
            .path("/users");
        then.status(200)
            .header("content-type", "application/json")
            .json_body(json!({ "name": "Hans" }));
    });

The request:

    let mut response = Request::get(&format!("http://{}/users", server.address()))
        .body(())
        .unwrap()
        .send()
        .unwrap();

    let user: Value =
        serde_json::from_str(&response.text().unwrap()).expect("cannot deserialize JSON");

Works well.

But

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().expect("Cant build Downloader");
            let bytes = downloader.get(&url).send().expect("Cant download");

crashed:

thread 'thread 'tokio-runtime-workertokio-runtime-worker' panicked at '' panicked at 'called Option::unwrap()on aNonevaluecalledOption::unwrap()on aNone value', ', .cargo/registry/src/index.crates.io-6f17d22bba15001f/ml-downloader-0.1.0/src/lib.rs/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ml-downloader-0.1.0/src/lib.rs::398398::4747

    fn send_once(&mut self) -> Result<Bytes, Error> {
        let response = self.inner.try_clone().unwrap().send()?;     << This unwrap()

I don`t know why but now the response is None...
Anyway, it looks like a better solution to remove this unwrap and respond with some Error code to prevent crashing .

Cheers!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.