authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 19:41:12 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-05-30 19:41:12 -07:00
log5db3ab392d43e25bc7fc0243fd7b131399cae7c8
treebdcf5ef925bf0e4b8e8986aa905a7be0b1f6c0a3
parentcc1a96881c7b15d850f9cd4b32019fd66fc8d3b0
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

add readUntilDelimiterOrEof


4 files changed, 16 insertions(+), 0 deletions(-)

AnyReadable.zig+1
...@@ -23,6 +23,7 @@ pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList;...@@ -23,6 +23,7 @@ pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList;
23pub const readAlloc = R.readAlloc;23pub const readAlloc = R.readAlloc;
24pub const readInt = R.readInt;24pub const readInt = R.readInt;
25pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;25pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;
26pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof;
2627
27pub const Error = ReadError; // std compat28pub const Error = ReadError; // std compat
28pub const ReadError = anyerror;29pub const ReadError = anyerror;
buffered_reader.zig+1
...@@ -34,6 +34,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty...@@ -34,6 +34,7 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty
34 pub const readAlloc = R.readAlloc;34 pub const readAlloc = R.readAlloc;
35 pub const readInt = R.readInt;35 pub const readInt = R.readInt;
36 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;36 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;
37 pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof;
3738
38 pub const ReadError = ReaderType.ReadError;39 pub const ReadError = ReaderType.ReadError;
39 pub fn read(self: *Self, dest: []u8) ReadError!usize {40 pub fn read(self: *Self, dest: []u8) ReadError!usize {
fixed_buffer_stream.zig+1
...@@ -43,6 +43,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {...@@ -43,6 +43,7 @@ pub fn FixedBufferStream(comptime Buffer: type) type {
43 pub const readAlloc = R.readAlloc;43 pub const readAlloc = R.readAlloc;
44 pub const readInt = R.readInt;44 pub const readInt = R.readInt;
45 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;45 pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc;
46 pub const readUntilDelimiterOrEof = R.readUntilDelimiterOrEof;
4647
47 pub const ReadError = error{};48 pub const ReadError = error{};
48 pub fn read(self: *Self, dest: []u8) ReadError!usize {49 pub fn read(self: *Self, dest: []u8) ReadError!usize {
nio.zig+13
...@@ -181,6 +181,19 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type {...@@ -181,6 +181,19 @@ pub fn Readable(T: type, this_kind: enum { _var, _const, _bare }) type {
181 _ = try readUntilDelimitersArrayList(self, &list, needle, max_size);181 _ = try readUntilDelimitersArrayList(self, &list, needle, max_size);
182 return list.toOwnedSlice();182 return list.toOwnedSlice();
183 }183 }
184
185 /// Returned slice is not suffixed by needle but buf will contain it.
186 pub fn readUntilDelimiterOrEof(self: Self, buf: []u8, needle: u8) !?[]u8 {
187 for (buf, 0..) |*c, i| {
188 const b = try readByte(self);
189 c.* = b;
190 if (b == needle) {
191 if (i == 0) return null;
192 return buf[0..i];
193 }
194 }
195 return error.StreamTooLong;
196 }
184 };197 };
185}198}
186199