Zig Requires Chilkat v11.0.0+
Zig
Find a ZIP Entry by EntryID Using EntryById
See more Zip Examples
This example demonstrates how to use the EntryById method to retrieve a ZIP entry using its unique EntryID.
Each ZipEntry object has an EntryID property that uniquely identifies the entry within the currently open ZIP object.
This is useful when:
- An application stores EntryID values for later use
- ZIP entries need to be retrieved without searching by filename
- Multiple entries may have similar names or paths
The example:
- Opens a ZIP archive
-
Retrieves an entry using
EntryAt -
Saves the entry's
EntryID -
Uses
EntryByIdto retrieve the same entry later
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Open an existing ZIP archive.
const zip = try chilkat.Zip.init();
defer zip.deinit();
zip.openZip("example.zip") catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
// Retrieve the first entry in the ZIP archive.
const entry = try chilkat.ZipEntry.init();
defer entry.deinit();
zip.entryAt(0, entry) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
std.debug.print("Original entry:\n", .{});
std.debug.print(" FileName: {s}\n", .{try entry.getFileName(alloc)});
std.debug.print(" EntryID: {d}\n", .{entry.getEntryID()});
std.debug.print("\n", .{});
// Save the EntryID for later use.
const entry_id = entry.getEntryID();
// Create another ZipEntry object.
const entry2 = try chilkat.ZipEntry.init();
defer entry2.deinit();
// Retrieve the same entry using EntryById.
zip.entryById(entry_id, entry2) catch {
std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
return;
};
std.debug.print("Entry retrieved by EntryID:\n", .{});
std.debug.print(" FileName: {s}\n", .{try entry2.getFileName(alloc)});
std.debug.print(" EntryID: {d}\n", .{entry2.getEntryID()});
std.debug.print("\n", .{});
// The filenames and EntryID values should match.
zip.closeZip();
std.debug.print("Done.\n", .{});
}