Sample code for 30+ languages & platforms
Zig

Unzip a .zip Archive

See more Zip Examples

Demonstrates how to open a .zip archive and unzip. The Unzip method extracts the files and directories from a .zip archive and recreates the directory tree rooted at the directory path passed to Unzip.

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.openZip("my_files.zip") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    // Returns the number of files and directories unzipped.
    // Unzips to /my_files, re-creating the directory tree
    // from the .zip.
    const unzip_count = zip.unzip("/my_files");
    if (unzip_count < 0) {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
    } else {
        std.debug.print("Success!\n", .{});
    }
}