aboutsummaryrefslogtreecommitdiff
path: root/lib/std/compress.zig
diff options
context:
space:
mode:
authorfn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com>2023-01-22 05:30:38 -0800
committerfn ⌃ ⌥ <70830482+FnControlOption@users.noreply.github.com>2023-01-22 05:30:38 -0800
commit6089ed9ee77ed034a39c2b557f4608cd8d779d3f (patch)
tree9eaf9d78ca73d8c2dc1654e1e8beacbed1551988 /lib/std/compress.zig
parentbe4468be371de34e90a86346b0f6da6f2d85bef4 (diff)
parentc0284e242f7d78955204dc8a627fecd45aa5e521 (diff)
downloadzig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.tar.gz
zig-6089ed9ee77ed034a39c2b557f4608cd8d779d3f.zip
Merge branch 'master' into crc
Diffstat (limited to 'lib/std/compress.zig')
-rw-r--r--lib/std/compress.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/std/compress.zig b/lib/std/compress.zig
index 7fa25175d5..3c52002cfc 100644
--- a/lib/std/compress.zig
+++ b/lib/std/compress.zig
@@ -4,6 +4,36 @@ 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;