| author | |
| committer | |
| log | 0bd9cc0259a15a5b78bfe2889a9866800560067d |
| tree | 8f2eb2daff638ff95efe66b604ab47c0715bcfc0 |
| parent | 9723d6d1d232b8a186366fc780ed1dac3513a74d |
| signature |
2 files changed, 29 insertions(+), 0 deletions(-)
counting_writer.zig created+27| ... | @@ -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 | } | ||
nio.zig+2| ... | @@ -289,3 +289,5 @@ pub const FixedBufferStream = @import("./fixed_buffer_stream.zig").FixedBufferSt | ... | @@ -289,3 +289,5 @@ pub const FixedBufferStream = @import("./fixed_buffer_stream.zig").FixedBufferSt |
| 289 | pub const BufferedReader = @import("./buffered_reader.zig").BufferedReader; | 289 | pub const BufferedReader = @import("./buffered_reader.zig").BufferedReader; |
| 290 | 290 | ||
| 291 | pub const BufferedWriter = @import("./buffered_writer.zig").BufferedWriter; | 291 | pub const BufferedWriter = @import("./buffered_writer.zig").BufferedWriter; |
| 292 | |||
| 293 | pub const CountingWriter = @import("./counting_writer.zig").CountingWriter; |