Rust Requires Chilkat v11.0.0+
Rust
Create a Zip Entirely in Memory
See more Zip Examples
Demonstrates how to create a .zip from in-memory byte data and strings, and to write the .zip to an in-memory image.Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let crypt = chilkat::Crypt2::new();
let zip = chilkat::Zip::new();
if zip.new_zip("test.zip").is_err() {
println!("{}", zip.last_error_text());
return;
}
// Add the bytes 0x00 0x01 0x02 0x03 ... 0x0F as a file in the .zip
let bd = chilkat::BinData::new();
let _ = bd.append_encoded("000102030405060708090A0B0C0D0E0F", "hex");
let _ = zip.add_bd("binaryData.dat", &bd);
// Add the string "Hello World!" to the .zip
let _ = zip.add_string("helloWorld.txt", "Hello World!", "utf-8");
zip_file_in_memory = zip.write_to_memory();
// We could save these files to a file, and it is a valid .zip
let fac = chilkat::FileAccess::new();
if fac.write_entire_file("test.zip", &zip_file_in_memory).is_err() {
println!("{}", fac.last_error_text());
return;
}
println!("Zip Created!");