Zig Requires Chilkat v11.0.0+
Zig
Change a Filename before Unzipping
See more Zip Examples
How to open a zip and modify the filename of one or more files within the zip before unzipping.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const zip = try chilkat.Zip.init();
defer zip.deinit();
success = if (zip.openZip("test.zip")) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
success = zip.entryOf("hamlet.xml", entry);
if (!success) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
entry.setFileName("hamlet2.xml");
success = zip.entryOf("helloWorld.pl", entry);
if (!success) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
entry.setFileName("hw.pl");
// Now unzip to the "test" subdirectory, under our current
// working directory:
const num_files_unzipped = zip.unzip("test");
if (num_files_unzipped < 0) {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
}
// The filenames within the .zip are unchanged, but it unzipped
// test/hw.pl and test/hamlet2.xml
}