The readAll() functions seem to cause significant confusion and doubtless lead to people writing bugs if they are not aware that of the silent truncation behavior if the provided buffer is not large enough to hold the entire file.
One attempt to fix this was: #20017, but I do not think this is the correct approach to take design-wise. (See #20017 (review))
The path I personally think makes the most sense here would be to remove existing readAll() style functions and replace them with a single std.io.Reader.streamUntilEof() similar to the very nice and flexible streamUntilDelimiter() API that was proposed in #15528 and implemented in #15762.
Similar to the examples given in that proposal, streamUntilEof() in combination with an std.BoundedArray() would be able to completely replace readAll().
The cases that are a bit trickier to handle with streamUntilEof() include std.fs.File.preadAll(), readvAll(), and preadvAll().
I think that preadAll() could be replaced with a std.fs.File.preader(offset) function that returns a reader which starts at the given offset and uses pread syscalls. This could then be used with the general Reader.streamUntilEof() function proposed above.
For File.readvAll() and File.preadvAll() it wouldn't make any sense to try and expose an equivalent Reader API. Instead, I think a simple rename plus better documentation would suffice. I propose File.readvFillBuffers() and File.preadvFillBuffers() for new names that don't imply the entire file will be read if the file size is larger than the buffer size.
The
readAll()functions seem to cause significant confusion and doubtless lead to people writing bugs if they are not aware that of the silent truncation behavior if the provided buffer is not large enough to hold the entire file.One attempt to fix this was: #20017, but I do not think this is the correct approach to take design-wise. (See #20017 (review))
The path I personally think makes the most sense here would be to remove existing
readAll()style functions and replace them with a singlestd.io.Reader.streamUntilEof()similar to the very nice and flexiblestreamUntilDelimiter()API that was proposed in #15528 and implemented in #15762.Similar to the examples given in that proposal,
streamUntilEof()in combination with anstd.BoundedArray()would be able to completely replacereadAll().The cases that are a bit trickier to handle with
streamUntilEof()includestd.fs.File.preadAll(),readvAll(), andpreadvAll().I think that
preadAll()could be replaced with astd.fs.File.preader(offset)function that returns a reader which starts at the given offset and uses pread syscalls. This could then be used with the generalReader.streamUntilEof()function proposed above.For
File.readvAll()andFile.preadvAll()it wouldn't make any sense to try and expose an equivalent Reader API. Instead, I think a simple rename plus better documentation would suffice. I proposeFile.readvFillBuffers()andFile.preadvFillBuffers()for new names that don't imply the entire file will be read if the file size is larger than the buffer size.