Syndica / zstd.zig

Zig binding of Z Standard

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

zstd.zig

Zig binding of Z Standard based on v1.5.2

how to import

in your build.zig:

pub fn build(b: *std.Build) void {
    // ...

    const zstd_dep = b.dependency("zstd", opts);
    const zstd_mod = zstd_dep.module("zstd");
    const zstd_c_lib = zstd_dep.artifact("zstd");

    const exec = ...

    // link it
    exec.addModule("zstd", zstd_mod);
    exec.linkLibrary(zstd_c_lib);

    // ...
}

usage

const ZstdReader = @import("zstd").Reader;
...

pub fn main() {
    const path = ...

    const file = try std.fs.cwd().openFile(path, .{});
    defer file.close();

    const file_stat = try file.stat();
    const file_size: u64 = @intCast(file_stat.size);
    var memory = try std.os.mmap(
        null,
        file_size,
        std.os.PROT.READ,
        std.os.MAP.PRIVATE,
        file.handle,
        0,
    );
    var decompressed_stream = try ZstdReader.init(memory);
    var reader = decompressed_stream.reader();

    ...
}

About

Zig binding of Z Standard

License:MIT License


Languages

Language:Zig 100.0%