2020-09-07 18:07:27 +01:00
|
|
|
const std = @import("std.zig");
|
|
|
|
|
|
|
|
pub const deflate = @import("compress/deflate.zig");
|
2020-09-11 21:17:08 +01:00
|
|
|
pub const gzip = @import("compress/gzip.zig");
|
2020-09-07 18:07:27 +01:00
|
|
|
pub const zlib = @import("compress/zlib.zig");
|
|
|
|
|
2023-01-21 23:47:31 +00:00
|
|
|
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 };
|
|
|
|
}
|
|
|
|
|
2021-01-22 14:45:28 +00:00
|
|
|
test {
|
2022-01-09 01:12:00 +00:00
|
|
|
_ = deflate;
|
2020-09-11 21:17:08 +01:00
|
|
|
_ = gzip;
|
2020-09-07 18:07:27 +01:00
|
|
|
_ = zlib;
|
|
|
|
}
|