I’ve been studying the Io.Reader implementation.
I really like its zero-copy [1] API: take, toss, and peek.
That said, I’m struggling to understand how to use Io.Reader in this scenario:
I need to read an unknown-size line in a file.
Because the line size is unknown, I can’t guarantee that my .buffer will be big enough.
I was expecting Io.Reader to have a way of filling a buffer until a delimiter is detected.
Maybe something like Io.Reader.readSliceDelimiterExclusive()?
But I can’t seem to find anything like this.
What is the idiomatic approach for solving this problem?
I suspected that was the case but wasn’t sure. In that case I think that using Reader.streamDelimiter (or one of its variants) with a Writer.Allocating writer is pretty elegant :^)
I cannot know the maximum size of a line, and therefore I can’t size my buffer.
Would it work for you to catcherror.StreamTooLong and then process the partial read in some way?
I was looking at this exact problem the other day and at least for my use case, it works well enough to consider the end of the buffer as if there was a '\n’ at the end.