DoxigAlpha

HashedReader

Fields of this type

Fields

#
child_reader:ReaderType
hasher:HasherType

Functions in this namespace

Functions

#

= ReaderType.Error

Values

#
Error
= ReaderType.Error

Source

Implementation

#
pub fn HashedReader(ReaderType: type, HasherType: type) type {
    return struct {
        child_reader: ReaderType,
        hasher: HasherType,

        pub const Error = ReaderType.Error;
        pub const Reader = std.io.GenericReader(*@This(), Error, read);

        pub fn read(self: *@This(), buf: []u8) Error!usize {
            const amt = try self.child_reader.read(buf);
            self.hasher.update(buf[0..amt]);
            return amt;
        }

        pub fn reader(self: *@This()) Reader {
            return .{ .context = self };
        }
    };
}