Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Create Password Protected Zip containing a Single File.

See more Zip Examples

Create a password-protected .zip containing a single file. (This uses the older Zip 2.0 encryption scheme, which is weaker and not as secure as AES encryption, which Chilkat Zip also supports.)

Chilkat Zig Downloads

Zig
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();

    zip.newZip("test.zip") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

ERROR: Method not in the Zig package: Zip.SetPassword
    zip.ERROR();
    zip.setPasswordProtect(true);

    const save_extra_path = false;
    try zip.addFile("/temp/hamlet.xml", save_extra_path);

    zip.writeZipAndClose() catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Zip Created!\n", .{});
}