Skip to content

Syndica/zstd.zig

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Zig 100.0%