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 LZMA2 and LZMA compression library.
lzma2.zig is production-ready. The recommended method for applications and downstream libraries is to pin to the tagged stable release:
# Recommended: Tagged stable release (0.0.1)
zig fetch --save https://github.com/muhammad-fiaz/lzma2.zig/archive/refs/tags/0.0.1.tar.gz
# Alternative: Latest development build (main branch)
zig fetch --save git+https://github.com/muhammad-fiaz/lzma2.zig.gitThen expose the module in your build.zig:
const lzma2_dep = b.dependency("lzma2", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("lzma2", lzma2_dep.module("lzma2"));Compress and decompress data in just a few lines of idiomatic Zig:
const std = @import("std");
const lzma2 = @import("lzma2");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const payload = "Native LZMA2 compression in pure Zig 0.17.0! High-ratio dictionary encoding.";
// One-shot heap compression
const compressed = try lzma2.compress(allocator, payload, .{});
defer allocator.free(compressed);
// One-shot heap decompression
const restored = try lzma2.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});
}