ChainSafe/snappy.zig
Zig bindings for the Google Snappy compression library
6f99459b5b837fa18abb1be317d3ac868530f384
A Zig library providing bindings to the Google Snappy compression library. Snappy is a fast compression/decompression library that aims for high speeds and reasonable compression ratios.
zig fetch --save=snappy git+https://github.com/chainsafe/snappy.zig
This dependency includes:
"snappy"
module - a zig module providing idiomatic zig bindings"snappy"
artifact - the upstream snappy static library and headersbuild.zig
, add the module:const snappy_dep = b.dependency("snappy", .{});
const snappy_mod = snappy_dep.module("snappy");
const snappy_lib = snappy_dep.artifact("snappy");
const snappy = @import("snappy");
const input = "Hello, world!";
const compressed = try allocator.alloc(u8, snappy.maxCompressedLength(input.len));
defer allocator.free(compressed);
const compressed_len = try snappy.compress(input, compressed);
const uncompressed = try allocator.alloc(u8, try snappy.uncompressedLength(compressed[0..compressed_len]));
defer allocator.free(uncompressed);
const uncompressed_len = try snappy.uncompress(compressed[0..compressed_len], uncompressed);
compress(input: []const u8, compressed: []u8) Error!usize
: Compresses input data into compressed buffer. Returns compressed length.uncompress(compressed: []const u8, uncompressed: []u8) Error!usize
: Decompresses compressed data into uncompressed buffer. Returns uncompressed length.maxCompressedLength(source_length: usize) usize
: Returns the maximum possible compressed size for given input length.uncompressedLength(compressed: []const u8) Error!usize
: Returns the uncompressed length of compressed data.validateCompressedBuffer(compressed: []const u8) Error!void
: Validates if compressed data is valid.MIT