Zig Requires Chilkat v11.0.0+
Zig
Iterate over Matching Filenames
See more Zip Examples
Iterates over files within a .zip that match a pattern. In this case, the pattern is "*.pem". This example will open a .zip containing files of type .txt, .cer, .pem, and possibly others, and will iterate over only the .pem files.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// 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();
// Open a .zip containing PEM files, among other things..
zip.openZip("qa_data/certs/thawte-roots.zip") catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
var pem_str: [:0]const u8 = "";
const pattern = "*.pem";
var b_has_more_matches: bool = if (zip.entryMatching(pattern, entry)) true else |_| false;
while (b_has_more_matches) {
std.debug.print("Entry: {s}\n", .{try entry.getFileName(alloc)});
// Get the uncommpressed contents of the entry:
pem_str = try entry.unzipToString(alloc, 0, "utf-8");
std.debug.print("{s}\n", .{pem_str});
b_has_more_matches = if (entry.getNextMatch(pattern)) true else |_| false;
}
}