Sample code for 30+ languages & platforms
Rust

Download a Zip from a URL and OpenBd. (No .zip file is created)

See more Zip Examples

Demonstrates how to download a .zip from a URL, opens the Zip, and gets the contents of a file. No file is ever written.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let http = chilkat::Http::new();

let bd = chilkat::BinData::new();

// This URL is valid and can be tested...
let _ = http.quick_get_bd("https://chilkatdownload.com/example_data/hamlet.zip", &bd).is_ok();
if !http.last_method_success() {
    println!("{}", http.last_error_text());
    return;
}

let zip = chilkat::Zip::new();

// Open the zip from the bytes contained in bd.
if zip.open_bd(&bd).is_err() {
    println!("{}", zip.last_error_text());
    return;
}

// Get the entry for the file we want..
let entry = chilkat::ZipEntry::new();
if zip.entry_of("hamlet.xml", &entry).is_err() {
    println!("{}", zip.last_error_text());
    return;
}

// Convert all line endings to CRLF (if needed)
let line_ending_behavior = 2;
let Ok(xml_str) = entry.unzip_to_string(line_ending_behavior, "utf-8") else {
    println!("{}", entry.last_error_text());
    return;
};

// The XML in this case is about 274K, so let's just examine the last 20 lines...
let sb = chilkat::StringBuilder::new();
let _ = sb.append(&xml_str);

println!("{}", sb.last_n_lines(20, true).unwrap_or_default());