-
Notifications
You must be signed in to change notification settings - Fork 542
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add v1util.EstargzReadCloser utility.
This adds the first utility function we will need to start producing estargz layers.
- Loading branch information
Showing
40 changed files
with
3,423 additions
and
68 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -18,6 +18,10 @@ import ( | |
"bytes" | ||
"compress/gzip" | ||
"io" | ||
"io/ioutil" | ||
|
||
"github.com/containerd/stargz-snapshotter/estargz" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
) | ||
|
||
var gzipMagicHeader = []byte{'\x1f', '\x8b'} | ||
|
@@ -80,6 +84,27 @@ func GunzipReadCloser(r io.ReadCloser) (io.ReadCloser, error) { | |
}, nil | ||
} | ||
|
||
// EstargzReadCloser reads uncompressed input data from the io.ReadCloser and | ||
// returns an io.ReadCloser from which compressed data may be read. | ||
// Refer to estargz for the options: | ||
// https://pkg.go.dev/github.com/containerd/[email protected]/estargz#Option | ||
func EstargzReadCloser(r io.ReadCloser, opts ...estargz.Option) (io.ReadCloser, v1.Hash, error) { | ||
defer r.Close() | ||
|
||
bs, err := ioutil.ReadAll(r) | ||
if err != nil { | ||
return nil, v1.Hash{}, err | ||
} | ||
br := bytes.NewReader(bs) | ||
|
||
rc, d, err := estargz.Build(io.NewSectionReader(br, 0, int64(len(bs))), nil, opts...) | ||
if err != nil { | ||
return nil, v1.Hash{}, err | ||
} | ||
h, err := v1.NewHash(d.String()) | ||
return rc, h, err | ||
} | ||
|
||
// IsGzipped detects whether the input stream is compressed. | ||
func IsGzipped(r io.Reader) (bool, error) { | ||
magicHeader := make([]byte, 2) | ||
|
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
202 changes: 202 additions & 0 deletions
202
vendor/github.com/containerd/stargz-snapshotter/estargz/LICENSE
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.