Sample code for 30+ languages & platforms
Zig

Create Self-Extracting Executable (Windows-only)

Demonstrates how to create a Windows self-extracting EXE.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

const ZipEvents = struct {
    // Called periodically while a Chilkat method is running
    // (frequency controlled by the HeartbeatMs property).
    pub fn abortCheck(_: *ZipEvents) bool {
        return false; // return true to abort the method in progress
    }

    pub fn percentDone(_: *ZipEvents, pct: i32) bool {
        std.debug.print("Percent Done: {d}\n", .{pct});
        // Explicitly abort at 25% or greater.
        // Remove this to allow for the HTTP download to run to completion.
        if (pct > 25) {
            return true; // abort the Chilkat method in progress
        }
        return false; // return true to abort the method in progress
    }

    pub fn progressInfo(_: *ZipEvents, name: [:0]const u8, value: [:0]const u8) void {
        std.debug.print("{s}: {s}\n", .{ name, value });
    }
};

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();
    var zip_events = ZipEvents{};
    zip.setEventHandler(&zip_events);

    // Initialize the zip object.  Because we're creating
    // a self-extracting EXE in this example, the filename
    // passed to NewZip will never actually be created.
    zip.newZip("notUsed.zip") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };

    // Append a directory tree.  The AppendFiles does
    // not read the file contents or append them to the zip
    // object in memory.  It simply appends references
    // to the files so that when WriteExe (or WriteZipAndClose,
    // or WriteZip, etc.) is called, the files are compressed
    // and added to the archive.
    const recurse = true;
    zip.appendFiles("c:/temp/a/*", recurse) catch {};

    // Write "sfx.exe"
    zip.writeExe("c:/temp/sfx.exe") catch {
        std.debug.print("{s}\n", .{try zip.getLastErrorText(alloc)});
        return;
    };
}