19767, "mppf", "I/O module: readAll / readFile", "2022-05-06T14:49:32Z"
This is a spin-off from discussion in #19496.
This issue proposes a separate function to read all of the data in a channel (from the current position to the end) and to return it as a string or bytes.
readAll
or readFile
have been suggested as names. I like readAll
better because a channel isn't necessarily working with the file (at least I wouldn't refer to a pipe or socket as a file in regular conversation) and because a channel can have represent only a portion of a file.
Here is a sketch at what this function might look like:
// reads up until EOF and returns whatever data was read in a string or bytes
// t can be string or bytes
proc reader.readAll(type t=string): t throws;
// Same as the above but updates a string/bytes argument.
proc reader.readAll(ref s: string): void throws;
proc reader.readAll(ref s: bytes): void throws;