Pure Native Zig (0.17.0)
Engineered from first principles in native Zig without `@cImport`, C compiler requirements, or external runtime dependencies.
Production-ready native Zig XZ container compression library.
xz.zig is production-ready. The recommended method for production applications is pinning to the tagged stable release:
# Recommended: Tagged stable release (0.0.1)
zig fetch --save https://github.com/muhammad-fiaz/xz.zig/archive/refs/tags/0.0.1.tar.gz
# Alternative: Latest development build (main branch)
zig fetch --save git+https://github.com/muhammad-fiaz/xz.zig.gitThen expose the module in your build.zig:
const xz_dep = b.dependency("xz", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("xz", xz_dep.module("xz"));Compress and decompress data in just a few lines of idiomatic Zig:
const std = @import("std");
const xz = @import("xz");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const payload = "Native XZ container compression in pure Zig 0.17.0! High-ratio dictionary encoding with CRC64.";
// One-shot heap compression with standard CRC64 integrity check
const compressed = try xz.compress(allocator, payload, .{ .check = .crc64 });
defer allocator.free(compressed);
// One-shot heap decompression
const restored = try xz.decompress(allocator, compressed, .{});
defer allocator.free(restored);
std.debug.print("Original size: {d} bytes\n", .{payload.len});
std.debug.print("Compressed size: {d} bytes\n", .{compressed.len});
std.debug.print("Restored: {s}\n", .{restored});
}