1mod builder_utils;
2mod bytes_aggregator;
3mod config;
4mod core;
5mod file_writer;
6mod filename_utils;
7mod from_state;
8mod info;
9mod progress_state;
10mod setup;
11#[cfg(test)]
12mod tests;
13mod throttle;
14
15use crate::http::{from_state::HttpDownloaderFromStateBuilder, progress_state::ProgressState};
16use config::HttpDownloadConfig;
17use info::HttpDownloadInfo;
18use reqwest::Client;
19use setup::HttpDownloaderSetupBuilder;
20use std::sync::Arc;
21
22pub struct HttpDownloader {
23 client: Arc<Client>,
24 raw_url: Arc<String>,
25 pub info: HttpDownloadInfo,
26 pub mode: HttpDownloadMode,
27 config: HttpDownloadConfig,
28 byte_ranges: Vec<(u64, u64)>,
29}
30
31impl HttpDownloader {
32 pub fn setup() -> HttpDownloaderSetupBuilder<setup::ClientRequired> {
33 HttpDownloaderSetupBuilder::default()
34 }
35
36 pub fn from_state(
37 filename: &str,
38 ) -> HttpDownloaderFromStateBuilder<from_state::ClientRequired> {
39 HttpDownloaderFromStateBuilder::new(String::from(filename))
40 }
41
42 pub fn mode(self) -> HttpDownloadMode {
43 self.mode
44 }
45
46 pub fn change_speed_limit(&self, kilobytes_per_second: Option<u64>) {
47 let throttle_speed = if kilobytes_per_second == None {
48 None
49 } else {
50 Some(kilobytes_per_second.unwrap() * 1024)
51 };
52
53 self.config
54 .throttle_config
55 .change_throttle_speed(throttle_speed, self.config.tasks_count as u64);
56 }
57}
58
59#[derive(Debug, PartialEq)]
60pub enum HttpDownloadMode {
61 NonResumable,
62 ResumableStream,
63 ResumableMultithread,
64}
65
66#[derive(Debug)]
67pub enum HttpDownloaderSetupErrors {
68 InvalidThreadsCount,
69}