authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-06-05 13:46:26 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2022-06-05 13:46:26 -07:00
log89bee5bad3c6f0cab3ab87942b5f653cc3d0ac33
treeb4782eff2bbb875f304171a82f36454276370065
parent596432af98c7cfd04047b9c885871e0237d34bed

remove HashWriter, is in std now


1 files changed, 2 insertions(+), 22 deletions(-)

src/lib.zig+2-22
......@@ -170,10 +170,9 @@ pub fn hashFile(alloc: std.mem.Allocator, dir: std.fs.Dir, sub_path: string, com
170170 .sha3_384 => hash.sha3.Sha3_384,
171171 .sha3_512 => hash.sha3.Sha3_512,
172172 };
173 const h = &Algo.init(.{});
173 var h = Algo.init(.{});
174174 var out: [Algo.digest_length]u8 = undefined;
175 var hw = HashWriter(Algo){ .h = h };
176 try pipe(file.reader(), hw.writer());
175 try pipe(file.reader(), h.writer());
177176 h.final(&out);
178177
179178 var res: [Algo.digest_length * 2]u8 = undefined;
......@@ -182,25 +181,6 @@ pub fn hashFile(alloc: std.mem.Allocator, dir: std.fs.Dir, sub_path: string, com
182181 return try alloc.dupe(u8, &res);
183182}
184183
185fn HashWriter(comptime T: type) type {
186 return struct {
187 h: *T,
188
189 const Self = @This();
190 pub const Error = error{};
191 pub const Writer = std.io.Writer(*Self, Error, write);
192
193 fn write(self: *Self, bytes: []const u8) Error!usize {
194 self.h.update(bytes);
195 return bytes.len;
196 }
197
198 pub fn writer(self: *Self) Writer {
199 return .{ .context = self };
200 }
201 };
202}
203
204184pub fn pipe(reader_from: anytype, writer_to: anytype) !void {
205185 var buf: [std.mem.page_size]u8 = undefined;
206186 var fifo = std.fifo.LinearFifo(u8, .Slice).init(&buf);