[][src]Struct manic::Downloader

pub struct Downloader { /* fields omitted */ }

Implementations

impl Downloader[src]

pub async fn new(url: &str, workers: u8) -> Result<Self>[src]

Create a new downloader

Arguments

  • url - URL of the file
  • workers - amount of concurrent tasks

Examples

use manic::Downloader;
    // If only one TLS feature is enabled
    let downloader = Downloader::new("https://crates.io", 5).await?;

pub fn get_filename(url: &Url) -> Result<String>[src]

Get filename from the url, returns an error if the url contains no filename

Arguments

  • url - &str with the url

Example

use manic::Downloader;
use manic::Error;
    let url = manic::Url::parse("http://test.rs/test.zip")?;
    let name = Downloader::get_filename(&url)?;
    assert_eq!("test.zip", name);

pub fn progress_bar(&mut self) -> &mut Self[src]

Enable progress reporting

pub fn bar_style(&self, style: ProgressStyle)[src]

Set the progress bar style

pub fn verify(&mut self, hash: Hash) -> Self[src]

Add a SHA checksum to verify against

Arguments

  • hash - Hash to verify against

pub async fn download(&self) -> Result<Vec<u8>>[src]

Download the file

Example

use manic::Downloader;
use manic::Error;
let client = Downloader::new("https://crates.io", 5).await?;
let result = client.download().await?;

pub async fn download_and_verify(&self) -> Result<Vec<u8>>[src]

Download and verify the file

Example

use manic::Downloader;
use manic::Error;
let client = Downloader::new("https://crates.io", 5).await?;
let result = client.download_and_verify().await?;

pub async fn download_and_save(&self, path: &str, verify: bool) -> Result<()>[src]

Used to download, save to a file and verify against a SHA256 sum, returns an error if the connection fails or if the sum doesn't match the one provided

Arguments

  • path - path to save the file to, if it's a directory then the original filename is used
  • verify - set true to verify the file against the hash

Example

use manic::Downloader;
use manic::Error;
use manic::Hash;
#[tokio::main]
async fn main() -> Result<(), Error> {
    let hash = Hash::SHA256("039058c6f2c0cb492c533b0a4d14ef77cc0f78abccced5287d84a1a2011cfb81".to_string());
    let client = Downloader::new("https://crates.io", 5).await?.verify(hash);
    client.download_and_save("~/Downloads", true).await?;
    Ok(())
 }

Trait Implementations

impl Clone for Downloader[src]

impl Debug for Downloader[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithSubscriber for T[src]