mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 15:42:49 +00:00
f85c01d4c7
From RFC 1952: > If FHCRC is set, a CRC16 for the gzip header is present, > immediately before the compressed data. The CRC16 consists > of the two least significant bytes of the CRC32 for all > bytes of the gzip header up to and not including the CRC16.
42 lines
999 B
Zig
42 lines
999 B
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 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;
|
|
}
|