fast_down/core/
auto.rs

1use super::{multi, single, DownloadResult};
2use crate::{ProgressEntry, RandWriter, SeqWriter};
3use core::time::Duration;
4use reqwest::{Client, IntoUrl};
5
6#[derive(Debug, Clone)]
7pub struct DownloadOptions {
8    pub threads: usize,
9    pub client: Client,
10    pub can_fast_download: bool,
11    pub download_chunks: Vec<ProgressEntry>,
12    pub retry_gap: Duration,
13    pub file_size: u64,
14}
15
16pub async fn download(
17    url: impl IntoUrl,
18    seq_writer: impl SeqWriter + 'static,
19    rand_writer: impl RandWriter + 'static,
20    options: DownloadOptions,
21) -> Result<DownloadResult, reqwest::Error> {
22    if options.can_fast_download {
23        multi::download(
24            url,
25            rand_writer,
26            multi::DownloadOptions {
27                client: options.client,
28                threads: options.threads,
29                download_chunks: options.download_chunks,
30                retry_gap: options.retry_gap,
31            },
32        )
33        .await
34    } else {
35        single::download(
36            url,
37            seq_writer,
38            single::DownloadOptions {
39                client: options.client,
40                retry_gap: options.retry_gap,
41            },
42        )
43        .await
44    }
45}