Rust
Rust
Example: Http.ResumeDownload method
Demonstrates theResumeDownload method.
Chilkat Rust Downloads
let mut success = false;
let http = chilkat::Http::new();
http.set_keep_response_body(true);
// To demonstrate resuming a download, we've created a file on the chilkatsoft.com
// web server that contains the first 82,379 bytes of the full 279,658 bytes of the hamlet.xml file.
// We'll first download the partial file, and pretend it was a previous incomplete attempt to download the entire file.
let local_file_path = "c:/temp/qa_output/hamlet.xml".to_string();
success = http.download("https://www.chilkatsoft.com/testData/hamlet_partial.xml", &local_file_path).is_ok();
if !success {
println!("{}", http.last_error_text());
return;
}
// Download the remainder of hamlet.xml.
success = http.resume_download("https://www.chilkatsoft.com/testData/hamlet.xml", &local_file_path).is_ok();
let status_code = http.last_status();
if !success {
if status_code == 0 {
// Unable to either send the request or get the response.
println!("{}", http.last_error_text());
} else {
// We got a response, but the status code was not in the 200s
println!("Response status code: {}", status_code);
// Examine the response body.
println!("Response body:");
println!("{}", http.last_response_body());
}
println!("Download failed.");
} else {
println!("Download success, response status = {}", status_code);
}
// The hamlet.xml file should be 279,658 bytes
let fac = chilkat::FileAccess::new();
println!("size of hamlet.xml: {}", fac.file_size(&local_file_path));
println!("Success.");