archive

package
v1.87.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TarEntries

func TarEntries(r io.Reader) ([]string, error)

TarEntries interprets the given io.Reader as a tar archive, outputting a list of filenames contained within it

Types

type MatchWalker added in v1.21.0

type MatchWalker struct {
	// contains filtered or unexported fields
}

MatchWalker walks a directory tree, only calling the wrapped WalkFunc if the path matches

func NewMatchWalker added in v1.21.0

func NewMatchWalker(patterns []*regexp.Regexp, walkFunc filepath.WalkFunc) *MatchWalker

NewMatchWalker returns a new MatchWalker given a slice of patterns and a filepath.WalkFunc

func (MatchWalker) Walk added in v1.21.0

func (m MatchWalker) Walk(path string, info os.FileInfo, err error) error

Walk walks the tree, filtering on regexp patterns

type TarBuilder

type TarBuilder struct {
	// contains filtered or unexported fields
}

TarBuilder writes a .tar archive to an io.Writer. The contents of the archive are determined by successive calls to `File` and `RecursiveDir`.

If an error occurs during processing, all subsequent calls to TarWriter will fail with that same error. The same error will be returned by `Err()`.

TarBuilder is **not** safe for concurrent use.

func NewTarBuilder

func NewTarBuilder(basePath string, w io.Writer) *TarBuilder

NewTarBuilder creates a TarBuilder that writes files from basePath on the filesystem to the given io.Writer

func (*TarBuilder) Close

func (t *TarBuilder) Close() error

Close finalizes the archive and releases any underlying resources. It should always be called, whether an error has been encountered in processing or not.

func (*TarBuilder) Err

func (t *TarBuilder) Err() error

Err returns the last error seen during operation of a TarBuilder. Once an error has been encountered, the TarBuilder will cease further operations. It is safe to make a series of calls, then just check `Err()` at the end.

func (*TarBuilder) File

func (t *TarBuilder) File(rel string, mustExist bool) error

File writes a single regular file to the archive. It is an error if the file exists, but is not a regular file - including symlinks.

If `mustExist` is set, an error is returned if the file doesn't exist. Otherwise, the error is hidden.

func (*TarBuilder) FileIfExist

func (t *TarBuilder) FileIfExist(rel string) error

FileIfExist is a helper for File that sets `mustExist` to false.

func (*TarBuilder) RecursiveDir

func (t *TarBuilder) RecursiveDir(rel string, mustExist bool, patterns ...*regexp.Regexp) error

RecursiveDir adds a complete directory to the archive, including all subdirectories and any regular files in the tree. Anything that is not a regular file (including symlinks, etc) will be **skipped**.

If `mustExist` is true, an error is returned if the root directory doesn't exist. Otherwise, the error is hidden.

If patterns is non-empty, only those matching files and directories will be included. Otherwise, all are included.

func (*TarBuilder) RecursiveDirIfExist

func (t *TarBuilder) RecursiveDirIfExist(rel string, patterns ...*regexp.Regexp) error

RecursiveDirIfExist is a helper for RecursiveDir that sets `mustExist` to false.

func (*TarBuilder) VirtualFileWithContents added in v1.21.0

func (t *TarBuilder) VirtualFileWithContents(relPath string, contents *os.File) error

VirtualFileWithContents creates an entry at relPath with contents from the given file. This can be used to build a virtual directory structure inside the tar archive.

Jump to

Keyboard shortcuts

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