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

Unzip Text File to String

See more Zip Examples

Demonstrates how to open a .zip and extract the 1st file (assuming it's a text file) to a string variable.

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

    // Get the 1st file in the .zip
    const entry = try chilkat.ZipEntry.init();
    defer entry.deinit();
    zip.entryAt(0, entry) catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    const file_contents = try entry.unzipToString(alloc, 0, "utf-8");
    std.debug.print("{s}\n", .{file_contents});
}