archive

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0, MIT Imports: 20 Imported by: 0

Documentation

Overview

Package archive provides helper functions for dealing with archive files.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDirectory      = errors.New("not a directory")
	ErrDirNotExists      = errors.New("no such directory")
	ErrCannotCopyDir     = errors.New("cannot copy directory")
	ErrInvalidCopySource = errors.New("invalid copy source content")
)

Errors used or returned by this file.

Functions

func DecompressStream

func DecompressStream(archive io.Reader) (io.ReadCloser, error)

DecompressStream decompresses the archive and returns a ReaderCloser with the decompressed archive.

func FileInfoHeader

func FileInfoHeader(name string, fi os.FileInfo, link string) (*tar.Header, error)

FileInfoHeader creates a populated Header from fi.

func IsArchivePath

func IsArchivePath(path string) bool

IsArchivePath checks if the (possibly compressed) file at the given path starts with a tar file header.

func Unpack

func Unpack(ctx context.Context, decompressedArchive io.Reader, dest string, options *TarOptions) error

Unpack unpacks the decompressedArchive to dest with options.

func Untar

func Untar(ctx context.Context, tarArchive io.Reader, dest string, options *TarOptions) error

Untar reads a stream of bytes from `archive`, parses it as a tar archive, and unpacks it into the directory at `dest`.

Types

type TarOptions

type TarOptions struct {
	IncludeFiles    []string
	ExcludePatterns []string
	Logger          func(format string, args ...any)
}

type Tarballer

type Tarballer struct {
	FileInfoReporter func(fs.FileInfo)
	// contains filtered or unexported fields
}

Tarballer is a lower-level interface to TarWithOptions which gives the caller control over which goroutine the archiving operation executes on.

func NewTarballer

func NewTarballer(ctx context.Context, srcPath string, options *TarOptions, reporterFn func(fs.FileInfo)) (*Tarballer, error)

NewTarballer constructs a new tarballer. The arguments are the same as for TarWithOptions.

func Tar

func Tar(ctx context.Context, srcPath string, options *TarOptions, reporterFn func(fs.FileInfo)) (*Tarballer, error)

Tar creates an archive from the directory at `path`, only including files whose relative paths are included in `options.IncludeFiles` (if non-nil) or not in `options.ExcludePatterns`.

func (*Tarballer) Close

func (t *Tarballer) Close() error

Close closes the reader and writer of the Tarballer.

func (*Tarballer) Do

func (t *Tarballer) Do()

Do performs the archiving operation in the background. The resulting archive can be read from t.Reader(). Do should only be called once on each Tarballer instance.

func (*Tarballer) FileCount

func (t *Tarballer) FileCount() int64

FileCount returns the number of files added to the archive.

func (*Tarballer) Reader

func (t *Tarballer) Reader() io.ReadCloser

Reader returns the reader for the created archive.

func (*Tarballer) UnpackedSize

func (t *Tarballer) UnpackedSize() int64

UnpackedSize returns the total size of the files added to the archive.

Jump to

Keyboard shortcuts

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