You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The type name might need to be changed since it is the same as the method name, which can be confusing.
It is similar to the io.ReaderAt interface, but instead of writing to a buffer, it returns a new io.Reader. If there were any errors while creating the io.Reader, the error shall be returned in the Read method of io.Reader.
The major use case is when the underlying file is on a remote server, such as an HTTP server. A naive io.ReaderAt implementation have to make HTTP requests with the Range header for each ReadAt call, since it cannot predict how much bytes to read ahead. A user who wants to read a range of the file as a stream would either have to buffer the entire section of the file into memory using one ReadAt call, or make an HTTP request each time the buffer is drained, wasting time on round trips and HTTP overhead. Using the io.NewReaderAt interface, the user creates an io.Reader for the file section and then stream it, while the implementation needs to make only one HTTP request.
The text was updated successfully, but these errors were encountered:
I don't see any NewReaderAt methods in the standard library. It doesn't seem to make sense to add an interface type.
The discussion implies that you are suggesting that the HTTP server code should have a NewReaderAt method. Let's talk about that before talking adding an interface type.
We have no NewReader, NewWriter, etc interfaces in the standard library, and as Ian said we also have no NewReaderAt methods.
Note that defining an interface only gives a name to something you can already write yourself. So not having the interface in the standard library can't be holding back code you want to write.
For these reasons, this seems like a likely decline.
I propose to add the following interface type to package
io
:The type name might need to be changed since it is the same as the method name, which can be confusing.
It is similar to the io.ReaderAt interface, but instead of writing to a buffer, it returns a new io.Reader. If there were any errors while creating the io.Reader, the error shall be returned in the
Read
method ofio.Reader
.The major use case is when the underlying file is on a remote server, such as an HTTP server. A naive
io.ReaderAt
implementation have to make HTTP requests with theRange
header for eachReadAt
call, since it cannot predict how much bytes to read ahead. A user who wants to read a range of the file as a stream would either have to buffer the entire section of the file into memory using oneReadAt
call, or make an HTTP request each time the buffer is drained, wasting time on round trips and HTTP overhead. Using theio.NewReaderAt
interface, the user creates anio.Reader
for the file section and then stream it, while the implementation needs to make only one HTTP request.The text was updated successfully, but these errors were encountered: