authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-13 19:47:54 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-13 19:47:54 -07:00
log0bd9cc0259a15a5b78bfe2889a9866800560067d
tree8f2eb2daff638ff95efe66b604ab47c0715bcfc0
parent9723d6d1d232b8a186366fc780ed1dac3513a74d
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add CountingWriter


2 files changed, 29 insertions(+), 0 deletions(-)

counting_writer.zig created+27
...@@ -0,0 +1,27 @@
1const std = @import("std");
2const extras = @import("extras");
3const nio = @import("./nio.zig");
4
5pub 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
289pub const BufferedReader = @import("./buffered_reader.zig").BufferedReader;289pub const BufferedReader = @import("./buffered_reader.zig").BufferedReader;
290290
291pub const BufferedWriter = @import("./buffered_writer.zig").BufferedWriter;291pub const BufferedWriter = @import("./buffered_writer.zig").BufferedWriter;
292
293pub const CountingWriter = @import("./counting_writer.zig").CountingWriter;