Struct squid::download::Task
[−]
[src]
pub struct Task { /* fields omitted */ }
Represents a single file's download task.
Methods
impl Task
[src]
fn new<T>(target_url: T, options: &Options) -> Result<Task, Error> where T: Into<String>
Creates a new download task.
Errors
Returns Err(Error::InvalidOption(...))
when an option is improperly configured.
Returns Err(Error::Io(...))
when a filesystem IO-related operation fails.
Returns Err(Error::Http(...))
when an HTTP-related operation fails.
Returns Err(Error::Tls(...))
when the establishment of the TLS client fails.
Returns Err(Error::MissingResponseHeader(...))
when the server response is missing a
required header.
Returns Err(Error::EmptyTarget(...))
when the target content is reported by the server to
have a length of zero bytes.
Examples
let options = download::Options { output_directory: "./Downloads/".to_string(), ..Default::default() }; // let task = download::Task::new("https://www.google.com/", &options).unwrap();
fn start(&mut self) -> Result<&str, Error>
Starts the download.
Errors
Returns Err(Error::Http(...))
when an HTTP-related operation fails.
Returns Err(Error::Io(...))
when a filesystem IO-related operation fails.
Returns Err(Error::UnexpectedResponseLength(...))
when a response from the server
is not of the expected length.
Returns Err(Error::Internal)
when an internal unknown error has occurred. This usually
indicates a problem in thread management in concurrent download strategies.
Examples
// let task = download::Task::new("https://www.google.com/", &options).unwrap(); // let output_file_path = task.start().unwrap();
fn start_and_report<F>(&mut self, report: &F) -> Result<&str, Error> where F: Fn(Message)
Starts the download and reports back status changes via a supplied callback function.
Errors
Returns Err(Error::Http(...))
when an HTTP-related operation fails.
Returns Err(Error::Io(...))
when a filesystem IO-related operation fails.
Returns Err(Error::UnexpectedResponseLength(...))
when a response from the server
is not of the expected length.
Returns Err(Error::Internal)
when an internal unknown error has occurred. This usually
indicates a problem in thread management in concurrent download strategies.
Examples
// let task = download::Task::new("https://www.google.com/", &options).unwrap(); // let output_file_path = // task // .start_and_report(|message| println!(message)) // .unwrap();
fn options(&self) -> &Options
Gets a reference to the options container.
fn target_url(&self) -> &str
Gets a reference to the target URL.
fn target_content_length(&self) -> u64
Gets the target's content length (in bytes).
fn target_file_name(&self) -> Option<&str>
Gets a reference to the target's file name.
fn target_supports_partial_content(&self) -> bool
Indicates whether the target supports partial content fetching.
fn output_file_name(&self) -> &str
Gets the output file's name.
fn output_file_path(&self) -> &str
Gets the output file's path.