summaryrefslogtreecommitdiffstats
path: root/crates/common/download/examples/simple_download.rs
blob: e583b0ebb50dfcd67ba804de6de21852bc379d0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use anyhow::Result;
use download::DownloadInfo;
use download::Downloader;

/// This example shows how to use the `downlaoder`.
#[tokio::main]
async fn main() -> Result<()> {
    // Create Download metadata.
    let url_data = DownloadInfo::new(
        "https://file-examples-com.github.io/uploads/2017/02/file_example_CSV_5000.csv",
    );

    // Create downloader instance with desired file path and target directory.
    let downloader = Downloader::new("test_download", &None, "/tmp");

    // Call `download` method to get data from url.
    let () = downloader.download(&url_data).await?;

    // Call cleanup method to remove downloaded file if no longer necessary.
    let () = downloader.cleanup().await?;

    Ok(())
}