| author | |
| committer | |
| log | 133dea370171f39fd98f2d772abffcdb28e1b967 |
| tree | f3313c53d335338f4dd2a7674066341d2ccda092 |
| parent | 1a90f8f77b3e01150399d0fca057bc8e109bf7e2 |
| signature |
4 files changed, 39 insertions(+), 0 deletions(-)
AnyReadable.zig+3| ... | ... | @@ -24,6 +24,9 @@ pub const readAlloc = R.readAlloc; |
| 24 | 24 | pub const readInt = R.readInt; |
| 25 | 25 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 26 | 26 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; |
| 27 | pub const readExpected = R.readExpected; | |
| 28 | pub const skipBytes = R.skipBytes; | |
| 29 | pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof; | |
| 27 | 30 | |
| 28 | 31 | pub const Error = ReadError; // std compat |
| 29 | 32 | pub const ReadError = anyerror; |
buffered_reader.zig+3| ... | ... | @@ -35,6 +35,9 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty |
| 35 | 35 | pub const readInt = R.readInt; |
| 36 | 36 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 37 | 37 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; |
| 38 | pub const readExpected = R.readExpected; | |
| 39 | pub const skipBytes = R.skipBytes; | |
| 40 | pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof; | |
| 38 | 41 | |
| 39 | 42 | pub const ReadError = ReaderType.ReadError; |
| 40 | 43 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
fixed_buffer_stream.zig+3| ... | ... | @@ -44,6 +44,9 @@ pub fn FixedBufferStream(comptime Buffer: type) type { |
| 44 | 44 | pub const readInt = R.readInt; |
| 45 | 45 | pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; |
| 46 | 46 | pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof; |
| 47 | pub const readExpected = R.readExpected; | |
| 48 | pub const skipBytes = R.skipBytes; | |
| 49 | pub const skipUntilDelimiterOrEof = R.skipUntilDelimiterOrEof; | |
| 47 | 50 | |
| 48 | 51 | pub const ReadError = error{}; |
| 49 | 52 | pub fn read(self: *Self, dest: []u8) ReadError!usize { |
nio.zig+30| ... | ... | @@ -194,6 +194,36 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type { |
| 194 | 194 | } |
| 195 | 195 | return error.StreamTooLong; |
| 196 | 196 | } |
| 197 | ||
| 198 | pub fn readExpected(self: Self, expected: []const u8) !bool { | |
| 199 | for (expected) |item| { | |
| 200 | const actual = try readByte(self); | |
| 201 | if (actual != item) { | |
| 202 | return false; | |
| 203 | } | |
| 204 | } | |
| 205 | return true; | |
| 206 | } | |
| 207 | ||
| 208 | pub fn skipBytes(self: Self, num_bytes: u64, comptime options: struct { buf_size: usize = 512 }) anyerror!void { | |
| 209 | var buf: [options.buf_size]u8 = undefined; | |
| 210 | var remaining = num_bytes; | |
| 211 | while (remaining > 0) { | |
| 212 | const amt = @min(remaining, options.buf_size); | |
| 213 | try readNoEof(self, buf[0..amt]); | |
| 214 | remaining -= amt; | |
| 215 | } | |
| 216 | } | |
| 217 | ||
| 218 | pub fn skipUntilDelimiterOrEof(self: Self, delimiter: u8) anyerror!void { | |
| 219 | while (true) { | |
| 220 | const byte = self.readByte() catch |err| switch (err) { | |
| 221 | error.EndOfStream => return, | |
| 222 | else => |e| return e, | |
| 223 | }; | |
| 224 | if (byte == delimiter) return; | |
| 225 | } | |
| 226 | } | |
| 197 | 227 | }; |
| 198 | 228 | } |
| 199 | 229 |