authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-02-22 12:29:21+01:00
committergravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-02-22 12:29:21+01:00
logeb67fab2d9e8540b9052e4b0d3cd0149da9d9962
treee6e1cf529ecc1ef39799c6289c02e49ec8a5b58d
parentce1a590fc9f57cde58c973d27461209ea2c34d37

refactor according to Ian's review

https://github.com/ziglang/zig/pull/19032#pullrequestreview-1894702793

1 files changed, 16 insertions(+), 25 deletions(-)

lib/std/io/buffered_tee.zig+16-25
...@@ -1,24 +1,23 @@...@@ -1,24 +1,23 @@
1//! BufferedTee provides reader interface to the consumer. Data read by consumer
2//! is also written to the output. Output is hold lookahead_size bytes behind
3//! consumer. Allowing consumer to put back some bytes to be read again. On flush
4//! all consumed bytes are flushed to the output.
5//!
6//! input -> tee -> consumer
7//! |
8//! output
9//!
10//! input - underlying unbuffered reader
11//! output - writer, receives data read by consumer
12//! consumer - uses provided reader interface
13//!
14//! If lookahead_size is zero output always has same bytes as consumer.
15//!
16
17const std = @import("std");1const std = @import("std");
18const io = std.io;2const io = std.io;
19const assert = std.debug.assert;3const assert = std.debug.assert;
20const testing = std.testing;4const testing = std.testing;
215
6/// BufferedTee provides reader interface to the consumer. Data read by consumer
7/// is also written to the output. Output is hold lookahead_size bytes behind
8/// consumer. Allowing consumer to put back some bytes to be read again. On flush
9/// all consumed bytes are flushed to the output.
10///
11/// input -> tee -> consumer
12/// |
13/// output
14///
15/// input - underlying unbuffered reader
16/// output - writer, receives data read by consumer
17/// consumer - uses provided reader interface
18///
19/// If lookahead_size is zero output always has same bytes as consumer.
20///
22pub fn BufferedTee(21pub fn BufferedTee(
23 comptime buffer_size: usize, // internal buffer size in bytes22 comptime buffer_size: usize, // internal buffer size in bytes
24 comptime lookahead_size: usize, // lookahead, number of bytes to hold output behind consumer23 comptime lookahead_size: usize, // lookahead, number of bytes to hold output behind consumer
...@@ -130,15 +129,7 @@ pub fn bufferedTee(...@@ -130,15 +129,7 @@ pub fn bufferedTee(
130 @TypeOf(input),129 @TypeOf(input),
131 @TypeOf(output),130 @TypeOf(output),
132) {131) {
133 return BufferedTee(132 return .{ .input = input, .output = output };
134 buffer_size,
135 lookahead_size,
136 @TypeOf(input),
137 @TypeOf(output),
138 ){
139 .input = input,
140 .output = output,
141 };
142}133}
143134
144// Running test from std.io.BufferedReader on BufferedTee135// Running test from std.io.BufferedReader on BufferedTee