| ... | @@ -849,14 +849,27 @@ pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 { | ... | @@ -849,14 +849,27 @@ pub fn peekDelimiterInclusive(r: *Reader, delimiter: u8) DelimiterError![]u8 { |
| 849 | } | 849 | } |
| 850 | while (true) { | 850 | while (true) { |
| 851 | const content_len = r.end - r.seek; | 851 | const content_len = r.end - r.seek; |
| | 852 | if (r.buffer.len - content_len == 0) break; |
| 852 | try fillMore(r); | 853 | try fillMore(r); |
| 853 | if (r.buffer.len - content_len == 0) return error.StreamTooLong; | | |
| 854 | const seek = r.seek; | 854 | const seek = r.seek; |
| 855 | const contents = r.buffer[0..r.end]; | 855 | const contents = r.buffer[0..r.end]; |
| 856 | if (std.mem.findScalarPos(u8, contents, seek + content_len, delimiter)) |end| { | 856 | if (std.mem.findScalarPos(u8, contents, seek + content_len, delimiter)) |end| { |
| 857 | return contents[seek .. end + 1]; | 857 | return contents[seek .. end + 1]; |
| 858 | } | 858 | } |
| 859 | } | 859 | } |
| | 860 | // It might or might not be end of stream. There is no more buffer space |
| | 861 | // left to disambiguate. If `StreamTooLong` was added to `RebaseError` then |
| | 862 | // this logic could be replaced by removing the exit condition from the |
| | 863 | // above while loop. That error code would represent when `buffer` capacity |
| | 864 | // is too small for an operation, replacing the current use of asserts. |
| | 865 | var failing_writer = Writer.failing; |
| | 866 | while (r.vtable.stream(r, &failing_writer, .limited(1))) |n| { |
| | 867 | assert(n == 0); |
| | 868 | } else |err| switch (err) { |
| | 869 | error.WriteFailed => return error.StreamTooLong, |
| | 870 | error.ReadFailed => |e| return e, |
| | 871 | error.EndOfStream => |e| return e, |
| | 872 | } |
| 860 | } | 873 | } |
| 861 | | 874 | |
| 862 | /// Returns a slice of the next bytes of buffered data from the stream until | 875 | /// Returns a slice of the next bytes of buffered data from the stream until |