Sample code for 30+ languages & platforms
Rust

Gzip a File

See more Gzip Examples

Demonstrates how to create a .gz (gzipped file).

Chilkat Rust Downloads

Rust

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

let gzip = chilkat::Gzip::new();

// This will create a .gz such that when ungzipped by a tool such as 7-Zip,
// it will create "qa_data/hamlet.xml".
if gzip.compress_file("qa_data/hamlet.xml", "qa_output/hamlet.xml.gz").is_err() {
    println!("{}", gzip.last_error_text());
    return;
}

// Call CompressFile2 to explicitly specify the ungzip path
// For example, this will create a .gz such that when ungzipped by a tool such as 7-Zip,
// it will create "hamlet.xml".
let embedded_extract_path = "hamlet.xml".to_string();
if gzip.compress_file2("qa_data/hamlet.xml", &embedded_extract_path, "qa_output/hamlet2.xml.gz").is_err() {
    println!("{}", gzip.last_error_text());
    return;
}

println!("Success.");