Sample code for 30+ languages & platforms
Zig

Ungzip Base64 String

See more Gzip Examples

Suppose you have a gzip in base64 representation that contains a text file, such as XML. This example shows how to decompress and access the string.

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 assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const gzip = try chilkat.Gzip.init();
    defer gzip.deinit();

    const gzip_base64 = "H4sIAAAAAAAE ... X6aZjXO3EwAA";

    const bd = try chilkat.BinData.init();
    defer bd.deinit();
    try bd.appendEncoded(gzip_base64, "base64");

    gzip.uncompressBd(bd) catch {
        std.debug.print("{s}\n", .{try gzip.getLastErrorText(alloc)});
        return;
    };

    const str_xml = try bd.getString(alloc, "utf-8");
    std.debug.print("XML:\n", .{});
    std.debug.print("{s}\n", .{str_xml});
}