Merge pull request #7414 from dmcgowan/optimize-content-copy

Add reader option to local content reader at
This commit is contained in:
Phil Estes 2022-09-22 14:35:54 -04:00 committed by GitHub
commit de2164158e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -37,10 +37,16 @@ var bufPool = sync.Pool{
},
}
type reader interface {
Reader() io.Reader
}
// NewReader returns a io.Reader from a ReaderAt
func NewReader(ra ReaderAt) io.Reader {
rd := io.NewSectionReader(ra, 0, ra.Size())
return rd
if rd, ok := ra.(reader); ok {
return rd.Reader()
}
return io.NewSectionReader(ra, 0, ra.Size())
}
// ReadBlob retrieves the entire contents of the blob from the provider.

View File

@ -18,6 +18,7 @@ package local
import (
"fmt"
"io"
"os"
"github.com/containerd/containerd/content"
@ -65,3 +66,7 @@ func (ra sizeReaderAt) Size() int64 {
func (ra sizeReaderAt) Close() error {
return ra.fp.Close()
}
func (ra sizeReaderAt) Reader() io.Reader {
return io.LimitReader(ra.fp, ra.size)
}