
After some analysis, it was found that Content.Reader was generally redudant to an io.ReaderAt. This change removes `Content.Reader` in favor of a `Content.ReaderAt`. In general, `ReaderAt` can perform better over interfaces with indeterminant latency because it avoids remote state for reads. Where a reader is required, a helper is provided to convert it into an `io.SectionReader`. Signed-off-by: Stephen J Day <stephen.day@docker.com>
25 lines
441 B
Go
25 lines
441 B
Go
package local
|
|
|
|
import (
|
|
"os"
|
|
)
|
|
|
|
// readerat implements io.ReaderAt in a completely stateless manner by opening
|
|
// the referenced file for each call to ReadAt.
|
|
type sizeReaderAt struct {
|
|
size int64
|
|
fp *os.File
|
|
}
|
|
|
|
func (ra sizeReaderAt) ReadAt(p []byte, offset int64) (int, error) {
|
|
return ra.fp.ReadAt(p, offset)
|
|
}
|
|
|
|
func (ra sizeReaderAt) Size() int64 {
|
|
return ra.size
|
|
}
|
|
|
|
func (ra sizeReaderAt) Close() error {
|
|
return ra.fp.Close()
|
|
}
|