Rust Requires Chilkat v11.5.0+
Rust
Retrieve Metadata from a Gzip File
See more Gzip Examples
This example demonstrates how to use the GetGzipInfo method to retrieve metadata embedded within a Gzip file.
The method reads the Gzip header and extracts any available metadata, including the embedded filename, comment, and optional extra data. The extracted information is returned in a JsonObject.
Because these fields are optional, the example checks for the existence of each JSON member using HasMember before retrieving its value. This avoids attempting to access values that may not be present.
Chilkat Rust Downloads
// This example demonstrates how to retrieve metadata embedded in a Gzip file.
let gzip = chilkat::Gzip::new();
let json = chilkat::JsonObject::new();
// The Gzip file to examine:
let gz_path = "example.txt.gz".to_string();
// Get the metadata information:
if gzip.get_gzip_info(&gz_path, &json).is_err() {
println!("{}", gzip.last_error_text());
return;
}
// Output the JSON containing metadata:
println!("Gzip metadata JSON:");
println!("{}", json.emit().unwrap_or_default());
// Access individual fields only if they exist:
if json.has_member("filename") {
let filename = json.string_of("filename").unwrap_or_default();
println!("Filename: {}", filename);
}
if json.has_member("comment") {
let comment = json.string_of("comment").unwrap_or_default();
println!("Comment: {}", comment);
}
if json.has_member("extraData") {
let extra_data = json.string_of("extraData").unwrap_or_default();
println!("ExtraData (Base64): {}", extra_data);
}