| ... | @@ -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 | | | |
| 17 | const std = @import("std"); | 1 | const std = @import("std"); |
| 18 | const io = std.io; | 2 | const io = std.io; |
| 19 | const assert = std.debug.assert; | 3 | const assert = std.debug.assert; |
| 20 | const testing = std.testing; | 4 | const testing = std.testing; |
| 21 | | 5 | |
| | 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 | /// |
| 22 | pub fn BufferedTee( | 21 | pub fn BufferedTee( |
| 23 | comptime buffer_size: usize, // internal buffer size in bytes | 22 | comptime buffer_size: usize, // internal buffer size in bytes |
| 24 | comptime lookahead_size: usize, // lookahead, number of bytes to hold output behind consumer | 23 | 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 | } |
| 143 | | 134 | |
| 144 | // Running test from std.io.BufferedReader on BufferedTee | 135 | // Running test from std.io.BufferedReader on BufferedTee |