-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream a layer to s3 if possible, instead of getting it then sending it
- Loading branch information
Showing
2 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package s3 | ||
|
||
import ( | ||
"io" | ||
"os" | ||
|
||
"github.com/containerd/containerd/content" | ||
) | ||
|
||
func ReadSeekerFromReaderAt(ra content.ReaderAt) io.ReadSeeker { | ||
return &readerAtSeeker{ | ||
ReaderAt: ra, | ||
} | ||
} | ||
|
||
type readerAtSeeker struct { | ||
pos int64 | ||
content.ReaderAt | ||
} | ||
|
||
var _ io.ReadSeeker = &readerAtSeeker{} | ||
|
||
// Read according to offset position | ||
// Read reads up to len(p) bytes into p. It returns the number of bytes | ||
// read (0 <= n <= len(p)) and any error encountered. | ||
func (r *readerAtSeeker) Read(p []byte) (n int, err error) { | ||
// Delegate to ReadAt, using current position | ||
n, err = r.ReadAt(p, r.pos) | ||
if err == nil { | ||
// Move the position forward | ||
r.pos += int64(n) | ||
} | ||
return n, err | ||
} | ||
|
||
// Seek sets the offset for the next Read, interpreted according to whence: | ||
// io.SeekStart means relative to the origin of the file, io.SeekCurrent means | ||
// relative to the current offset, and io.SeekEnd means relative to the EOF. | ||
func (r *readerAtSeeker) Seek(offset int64, whence int) (int64, error) { | ||
var newPos int64 | ||
|
||
switch whence { | ||
case io.SeekStart: | ||
newPos = offset | ||
case io.SeekCurrent: | ||
newPos = r.pos + offset | ||
case io.SeekEnd: | ||
newPos = r.Size() + offset | ||
default: | ||
return 0, os.ErrInvalid | ||
} | ||
|
||
if newPos < 0 || newPos > r.Size() { | ||
return 0, os.ErrInvalid | ||
} | ||
|
||
r.pos = newPos | ||
return r.pos, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters