Pure Native Zig (0.17.0)
Engineered from first principles in native Zig without `@cImport`, C compiler requirements, or external runtime dependencies.
Pure Zig implementation of the LZ4 ecosystem targeting Zig 0.17.0. Zero C dependencies, zero overhead, memory-safe.
Add lz4.zig to your build.zig.zon:
# Stable Release
zig fetch --save https://github.com/muhammad-fiaz/lz4.zig/archive/refs/tags/0.0.1.tar.gz
# Latest / Dev / Nightly
zig fetch --save git+https://github.com/muhammad-fiaz/lz4.zig.gitThen expose the module in your build.zig:
const lz4_dep = b.dependency("lz4", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("lz4", lz4_dep.module("lz4"));Compress and decompress data in just a few lines of idiomatic Zig:
const std = @import("std");
const lz4 = @import("lz4");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
defer _ = gpa.deinit();
const allocator = gpa.allocator();
const raw_data = "LZ4 is an extremely fast lossless compression algorithm!";
// One-shot compression to a standard LZ4 frame
const compressed = try lz4.compress(allocator, raw_data);
defer allocator.free(compressed);
// One-shot decompression (handles frames and blocks automatically)
const restored = try lz4.decompress(allocator, compressed);
defer allocator.free(restored);
std.debug.print("Original size: {d} bytes\n", .{raw_data.len});
std.debug.print("Compressed size: {d} bytes\n", .{compressed.len});
std.debug.print("Restored: {s}\n", .{restored});
}