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 Google's Snappy compression format targeting Zig 0.17.0. Zero C dependencies, zero overhead, memory-safe.
Add snappy.zig to your build.zig.zon:
# 1. Stable Release (Tagged)
zig fetch --save https://github.com/muhammad-fiaz/snappy.zig/archive/refs/tags/0.0.1.tar.gz
# 2. Nightly / Latest Development URL
zig fetch --save git+https://github.com/muhammad-fiaz/snappy.zig.gitThen expose the module in your build.zig:
const snappy_dep = b.dependency("snappy", .{
.target = target,
.optimize = optimize,
});
exe.root_module.addImport("snappy", snappy_dep.module("snappy"));Compress and decompress data in just a few lines of idiomatic Zig:
const std = @import("std");
const snappy = @import("snappy");
pub fn main() !void {
const allocator = std.heap.page_allocator;
const raw_data = "Snappy is a compression/decompression library aimed at very high speeds!";
// One-shot framed compression (standard .sz stream format)
const compressed = try snappy.compress(allocator, raw_data);
defer allocator.free(compressed);
// One-shot decompression (handles framed streams and raw blocks automatically)
const restored = try snappy.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});
}