Struct parallel_getter::ParallelGetter [−][src]
pub struct ParallelGetter<'a, W: Write + 'a> { /* fields omitted */ }
Type for constructing parallel GET requests.
Example
extern crate reqwest; extern crate parallel_getter; use reqwest::Client; use parallel_getter::ParallelGetter; use std::fs::File; use std::path::PathBuf; use std::sync::Arc; let client = Arc::new(Client::new()); let mut file = File::create("new_file").unwrap(); ParallelGetter::new("url_here", &mut file) // Additional mirrors that can be used. .mirrors(&["mirror_a", "mirror_b"]) // Optional client to use for the request. .client(client) // Optional path to store the parts. .cache_path(PathBuf::from("/a/path/here")) // Number of theads to use. .threads(5) // threshold (length in bytes) to determine when multiple threads are required. .threshold_parallel(1 * 1024 * 1024) // threshold for defining when to store parts in memory or on disk. .threshold_memory(10 * 1024 * 1024) // Callback for monitoring progress. .callback(16, Box::new(|progress, total| { println!( "{} of {} KiB downloaded", progress / 1024, total / 1024 ); })) // Commit the parallel GET requests. .get();
Methods
impl<'a, W: Write> ParallelGetter<'a, W>
[src]
impl<'a, W: Write> ParallelGetter<'a, W>
pub fn new(url: &'a str, dest: &'a mut W) -> Self
[src]
pub fn new(url: &'a str, dest: &'a mut W) -> Self
Initialize a new ParallelGetter
Notes
- The
url
is the location which we will send a GET to. - The
dest
is where the completed file will be written to. - By default, 4 threads will be used.
pub fn get(self) -> Result<usize>
[src]
pub fn get(self) -> Result<usize>
Submit the parallel GET request.
pub fn cache_path(self, path: PathBuf) -> Self
[src]
pub fn cache_path(self, path: PathBuf) -> Self
If defined, downloads will be stored here instead of a temporary directory.
Notes
This is required to enable resumable downloads (not yet implemented).
pub fn callback(self, poll_ms: u64, func: Box<Fn(u64, u64)>) -> Self
[src]
pub fn callback(self, poll_ms: u64, func: Box<Fn(u64, u64)>) -> Self
Specify a callback for monitoring progress, to be polled at the given interval.
pub fn client(self, client: Arc<Client>) -> Self
[src]
pub fn client(self, client: Arc<Client>) -> Self
Allow the caller to provide their own Client
.
pub fn mirrors(self, mirrors: &'a [&'a str]) -> Self
[src]
pub fn mirrors(self, mirrors: &'a [&'a str]) -> Self
Specify additional URLs that point to the same content, to be used for boosted transfers.
pub fn retries(self, tries: u32) -> Self
[src]
pub fn retries(self, tries: u32) -> Self
Number of attempts to make before giving up.
pub fn threshold_memory(self, length: u64) -> Self
[src]
pub fn threshold_memory(self, length: u64) -> Self
If the length is less than this threshold, parts will be stored in memory.
pub fn threshold_parallel(self, bytes: u64) -> Self
[src]
pub fn threshold_parallel(self, bytes: u64) -> Self
If the length is less than this threshold, threads will not be used.
pub fn threads(self, threads: usize) -> Self
[src]
pub fn threads(self, threads: usize) -> Self
Number of threads to download a file with.
Auto Trait Implementations
impl<'a, W> !Send for ParallelGetter<'a, W>
impl<'a, W> !Send for ParallelGetter<'a, W>
impl<'a, W> !Sync for ParallelGetter<'a, W>
impl<'a, W> !Sync for ParallelGetter<'a, W>