Skip to content

Archive.zigAll in One archive/compression library for Zig.

Comprehensive compression and archive support for Zig with multiple algorithms and streaming capabilities

Archive.zig

Quick Example โ€‹

zig
const std = @import("std");
const archive = @import("archive");

pub fn main() !void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = gpa.allocator();

    // Compress data
    const input = "Hello, Archive.zig!";
    const compressed = try archive.compress(allocator, input, .gzip);
    defer allocator.free(compressed);

    // Decompress data
    const decompressed = try archive.decompress(allocator, compressed, .gzip);
    defer allocator.free(decompressed);

    std.debug.print("Original: {s}\n", .{input});
    std.debug.print("Compressed: {d} bytes\n", .{compressed.len});
    std.debug.print("Decompressed: {s}\n", .{decompressed});
}

Supported Algorithms โ€‹

AlgorithmExtensionDescriptionPerformance
gzip.gzGNU zip with CRC32Fast
zlib.zlibDeflate with Adler32Fast
deflate.deflateRaw deflateFastest
zstd.zstModern compressionVery Fast
lz4.lz4Ultra-fast compressionFastest
lzma.lzmaHigh compression ratioSlow
xz.xzLZMA2-basedSlow
tar.gz.tar.gzTAR + gzipFast
zip.zipZIP archive formatFast

Installation โ€‹

Add Archive.zig to your project with Zig's package manager:

bash
zig fetch --save https://github.com/muhammad-fiaz/archive.zig/archive/refs/tags/0.0.1.tar.gz

Then add to your build.zig:

zig
const archive = b.dependency("archive", .{
    .target = target,
    .optimize = optimize,
});

exe.root_module.addImport("archive", archive.module("archive"));

Why Archive.zig? โ€‹

  • ๐Ÿš€ Performance: Optimized implementations with minimal allocations
  • ๐Ÿ”ง Flexibility: Multiple algorithms and configuration options
  • ๐Ÿ“š Simple: Clean API that's easy to learn and use
  • ๐Ÿ›ก๏ธ Reliable: Comprehensive error handling and memory safety
  • ๐ŸŒ Portable: Cross-platform support including bare metal
  • ๐Ÿ“– Documented: Extensive documentation and examples

Released under the MIT License.