tarfile

package
v0.6.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: Apache-2.0 Imports: 16 Imported by: 9

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("image not found")
	// This needs to be kept in sync with the decompressor list
	SupportedExtensions = []string{".tar", ".tar.lz4", ".tar.bz2", ".tbz", ".tar.gz", ".tgz", ".tar.zst", ".tzst"}
	// The zstd decoder will attempt to use up to 1GB memory for streaming operations by default,
	// which is excessive and will OOM low-memory devices.
	// NOTE: This must be at least as large as the window size used when compressing tarballs, or you
	// will see a "window size exceeded" error when decompressing. The zstd CLI tool uses 4MB by
	// default; the --long option defaults to 27 or 128M, which is still too much for a Pi3. 32MB
	// (--long=25) has been tested to work acceptably while still compressing by an additional 3-6% on
	// our datasets.
	MaxDecoderMemory = uint64(1 << 25)
)

Functions

func FindImage

func FindImage(imagesDir string, imageRef name.Reference) (v1.Image, error)

FindImage checks tarball files in a given directory for a copy of the referenced image. The image reference must be a Tag, not a Digest. The image is retrieved from the first file (ordered by name) that it is found in; there is no preference in terms of compression format. If the image is not found in any file in the given directory, a NotFoundError is returned.

func GetOpener added in v0.5.1

func GetOpener(fileName string) (tarball.Opener, error)

GetOpener returns a function implementing the tarball.Opener interface. This is required because compressed tarballs are not seekable, and the image reader may need to seek backwards in the file to find a required layer. Instead of seeking backwards, it just closes and reopens the file. If the file format is not supported, an error is returned.

func MultiReadCloser

func MultiReadCloser(r io.ReadCloser, c io.Closer) io.ReadCloser

MultiReadCloser implements the ReadCloser interface for decompressors that need to be closed. Some decompressors implement a Close function that needs to be called to clean up resources or verify checksums, but we also need to ensure that the underlying file gets closed as well.

func SplitReadCloser

func SplitReadCloser(r io.Reader, c io.Closer) io.ReadCloser

SplitReadCloser implements the ReadCloser interface for decompressors that don't need to be closed. Some decompressors don't implement a Close function, so we just need to ensure that the underlying file gets closed.

func ZstdReadCloser

func ZstdReadCloser(r *zstd.Decoder, c io.Closer) io.ReadCloser

ZstdReadCloser implements the ReadCloser interface for zstd. The zstd decompressor's Close() method doesn't have a return value and therefore doesn't match the ReadCloser interface, so we have to wrap it in our own ReadCloser that doesn't expect a return value. We also need to close the underlying filehandle.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL