| ... | ... | @@ -0,0 +1,27 @@ |
| 1 | const std = @import("std"); |
| 2 | const extras = @import("extras"); |
| 3 | const nio = @import("./nio.zig"); |
| 4 | |
| 5 | pub fn CountingWriter(WriterType: type) type { |
| 6 | return struct { |
| 7 | backing_writer: WriterType, |
| 8 | bytes_written: u64, |
| 9 | |
| 10 | const Self = @This(); |
| 11 | |
| 12 | pub fn init(backing_writer: WriterType) Self { |
| 13 | return .{ |
| 14 | .backing_writer = backing_writer, |
| 15 | .bytes_written = 0, |
| 16 | }; |
| 17 | } |
| 18 | |
| 19 | pub const WriteError = extras.Pointee(WriterType).WriteError; |
| 20 | pub usingnamespace nio.Writable(@This(), ._var); |
| 21 | pub fn write(self: *Self, bytes: []const u8) WriteError!usize { |
| 22 | const len = try self.backing_writer.write(bytes); |
| 23 | self.bytes_written += len; |
| 24 | return len; |
| 25 | } |
| 26 | }; |
| 27 | } |