-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
io: add new stringreader struct #20893
Conversation
vlib/io/string_reader.v
Outdated
|
||
// StringReader is able to read data from a Reader interface and/or source string to a dynamically | ||
// growing buffer using a string builder. Unlike the BufferedReader, StringReader will | ||
// keep the entire contents of the buffer in memory, allowing the incoming data to be reused |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this reader keep the entire buffers content in memory, i think its a good to place limit on them, or it would grow uncontrollable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's a Reader, it's on the caller to control the size of the string. If it was a Writer, then yes, it would have to handle not allowing the string to run you out of memory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you want to control how many bytes are read in total, you can call ‘fill_buffer_until`. This function will only read a maximum amount of bytes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That said, it would be useful to provide methods to clear the buffer and offset. I'll add them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a line in the doc comment to make it more clear:
The StringReader will not set a maximum capacity to the string builders buffer and could grow very large.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work.
This pr adds a new StringReader struct to the
io
module.The
StringRedeader
is able to read data from a Reader interface and/or source string to a dynamically growing buffer using a string builder.Unlike the
BufferedReader
,StringReader
will keep the entire contents of the buffer in memory, allowing the incoming data to be reused and read in an efficient matter.The
StringReader
also implements theio.ReaderWriter
interface