mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
* add xz to std.compress * prefer importing std.zig by file name, to reduce reliance on the standard library being a special case. * extract some types from inside generic functions. These types are the same regardless of the generic parameters. * expose some more types in the std.compress.xz namespace. * rename xz.stream to xz.decompress * rename check.Kind to Check * use std.leb for LEB instead of a redundant implementation
43 lines
1 KiB
Zig
43 lines
1 KiB
Zig
const std = @import("std.zig");
|
|
|
|
pub const deflate = @import("compress/deflate.zig");
|
|
pub const gzip = @import("compress/gzip.zig");
|
|
pub const zlib = @import("compress/zlib.zig");
|
|
pub const xz = @import("compress/xz.zig");
|
|
|
|
pub fn HashedReader(
|
|
comptime ReaderType: anytype,
|
|
comptime HasherType: anytype,
|
|
) type {
|
|
return struct {
|
|
child_reader: ReaderType,
|
|
hasher: HasherType,
|
|
|
|
pub const Error = ReaderType.Error;
|
|
pub const Reader = std.io.Reader(*@This(), Error, read);
|
|
|
|
pub fn read(self: *@This(), buf: []u8) Error!usize {
|
|
const amt = try self.child_reader.read(buf);
|
|
self.hasher.update(buf);
|
|
return amt;
|
|
}
|
|
|
|
pub fn reader(self: *@This()) Reader {
|
|
return .{ .context = self };
|
|
}
|
|
};
|
|
}
|
|
|
|
pub fn hashedReader(
|
|
reader: anytype,
|
|
hasher: anytype,
|
|
) HashedReader(@TypeOf(reader), @TypeOf(hasher)) {
|
|
return .{ .child_reader = reader, .hasher = hasher };
|
|
}
|
|
|
|
test {
|
|
_ = deflate;
|
|
_ = gzip;
|
|
_ = zlib;
|
|
_ = xz;
|
|
}
|