authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-08 14:47:55 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-08 14:47:55 -07:00
logb85800a14c8dd942da21ad8765cd9c991c57b770
tree7fe7cc853af5c772ca849026dc38dc75f9ddc97d
parentd1b22241b2bc354b27c10a2bc42863030ec392df
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

Readable: add pipeTo(writable)


6 files changed, 14 insertions(+), 0 deletions(-)

AnyReadable.zig+1
......@@ -29,6 +29,7 @@ pub const readExpected = R.readExpected;
2929pub const readType = R.readType;
3030pub const skipBytes = R.skipBytes;
3131pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof;
32pub const pipeTo = R.pipeTo;
3233
3334pub const Error = ReadError; // std compat
3435pub const ReadError = anyerror;
buffered_reader.zig+1
......@@ -41,6 +41,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
4141 pub const readType = R.readType;
4242 pub const skipBytes = R.skipBytes;
4343 pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof;
44 pub const pipeTo = R.pipeTo;
4445
4546 pub const ReadError = extras.Pointee(ReaderType).ReadError;
4647 pub fn read(self: *Self, dest: []u8) ReadError!usize {
counting_reader.zig+1
......@@ -44,6 +44,7 @@ pub fn CountingReader(ReaderType: type) type {
4444 pub const readType = R.readType;
4545 pub const skipBytes = R.skipBytes;
4646 pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof;
47 pub const pipeTo = R.pipeTo;
4748
4849 pub const ReadError = extras.Pointee(ReaderType).ReadError;
4950
fixed_buffer_stream.zig+1
......@@ -49,6 +49,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
4949 pub const readType = R.readType;
5050 pub const skipBytes = R.skipBytes;
5151 pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof;
52 pub const pipeTo = R.pipeTo;
5253
5354 pub const ReadError = error{};
5455 pub fn read(self: *Self, dest: []u8) ReadError!usize {
limited_reader.zig+1
......@@ -44,6 +44,7 @@ pub fn LimitedReader(ReaderType: type) type {
4444 pub const readType = R.readType;
4545 pub const skipBytes = R.skipBytes;
4646 pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof;
47 pub const pipeTo = R.pipeTo;
4748
4849 pub const ReadError = extras.Pointee(ReaderType).ReadError;
4950
nio.zig+9
......@@ -261,6 +261,15 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type {
261261 if (byte == delimiter) return;
262262 }
263263 }
264
265 pub fn pipeTo(self: Self, writer: anytype) !void {
266 var buf: [4096]u8 = undefined;
267 while (true) {
268 const n = try self.read(&buf);
269 if (n == 0) break;
270 try writer.writeAll(buf[0..n]);
271 }
272 }
264273 };
265274}
266275