archive

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2014 License: Apache-2.0 Imports: 18 Imported by: 0

README

This code provides helper functions for dealing with archive files.

TODO: Move this to either pkg or (if not possible) to utils.

Documentation

Index

Constants

View Source
const (
	ChangeModify = iota
	ChangeAdd
	ChangeDelete
)

Variables

View Source
var (
	ErrNotImplemented = errors.New("Function not implemented")
)

Functions

func ApplyLayer added in v0.7.0

func ApplyLayer(dest string, layer ArchiveReader) error

ApplyLayer parses a diff in the standard layer format from `layer`, and applies it to the directory `dest`.

func ChangesSize added in v0.7.0

func ChangesSize(newDir string, changes []Change) int64

func CmdStream

func CmdStream(cmd *exec.Cmd, input io.Reader) (io.ReadCloser, error)

CmdStream executes a command, and returns its stdout as a stream. If the command fails to run or doesn't complete successfully, an error will be returned, including anything written on stderr.

func CompressStream added in v0.8.0

func CompressStream(dest io.WriteCloser, compression Compression) (io.WriteCloser, error)

func CopyFileWithTar

func CopyFileWithTar(src, dst string) (err error)

CopyFileWithTar emulates the behavior of the 'cp' command-line for a single file. It copies a regular file from path `src` to path `dst`, and preserves all its metadata.

If `dst` ends with a trailing slash '/', the final destination path will be `dst/base(src)`.

func CopyWithTar

func CopyWithTar(src, dst string) error

CopyWithTar creates a tar archive of filesystem path `src`, and unpacks it at filesystem path `dst`. The archive is streamed directly with fixed buffering and no intermediary disk IO.

func DecompressStream added in v0.7.3

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

func IsArchive added in v1.1.0

func IsArchive(header []byte) bool

func Tar

func Tar(path string, compression Compression) (io.ReadCloser, error)

Tar creates an archive from the directory at `path`, and returns it as a stream of bytes.

func TarUntar

func TarUntar(src string, dst string) error

TarUntar is a convenience function which calls Tar and Untar, with the output of one piped into the other. If either Tar or Untar fails, TarUntar aborts and returns the error.

func TarWithOptions added in v1.1.0

func TarWithOptions(srcPath string, options *TarOptions) (io.ReadCloser, error)

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

func Untar

func Untar(archive 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`. The archive may be compressed with one of the following algorithms:

identity (uncompressed), gzip, bzip2, xz.

If `dest` does not exist, it is created unless there are multiple entries in `archive`. In the latter case, an error is returned. If `dest` is an existing file, it gets overwritten. If `dest` is an existing directory, its files get merged (with overwrite for conflicting files).

func UntarPath

func UntarPath(src, dst string) error

UntarPath is a convenience function which looks for an archive at filesystem path `src`, and unpacks it at `dst`.

Types

type Archive

type Archive io.ReadCloser

func ExportChanges added in v0.7.0

func ExportChanges(dir string, changes []Change) (Archive, error)

func Generate added in v0.8.1

func Generate(input ...string) (Archive, error)

Generate generates a new archive from the content provided as input.

`files` is a sequence of path/content pairs. A new file is added to the archive for each pair. If the last pair is incomplete, the file is created with an empty content. For example:

Generate("foo.txt", "hello world", "emptyfile")

The above call will return an archive with 2 files:

  • ./foo.txt with content "hello world"
  • ./empty with empty content

FIXME: stream content instead of buffering FIXME: specify permissions and other archive metadata

type ArchiveReader added in v0.8.1

type ArchiveReader io.Reader

type Change added in v0.7.0

type Change struct {
	Path string
	Kind ChangeType
}

func Changes added in v0.7.0

func Changes(layers []string, rw string) ([]Change, error)

func ChangesDirs added in v0.7.0

func ChangesDirs(newDir, oldDir string) ([]Change, error)

Compare two directories and generate an array of Change objects describing the changes

func (*Change) String added in v0.7.0

func (change *Change) String() string

type ChangeType added in v0.7.0

type ChangeType int

type Compression

type Compression int
const (
	Uncompressed Compression = iota
	Bzip2
	Gzip
	Xz
)

func DetectCompression

func DetectCompression(source []byte) Compression

func (*Compression) Extension

func (compression *Compression) Extension() string

type FileInfo added in v0.7.0

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

func (*FileInfo) Changes added in v0.7.0

func (info *FileInfo) Changes(oldInfo *FileInfo) []Change

func (*FileInfo) LookUp added in v0.7.0

func (root *FileInfo) LookUp(path string) *FileInfo

type TarOptions added in v0.7.0

type TarOptions struct {
	Includes    []string
	Excludes    []string
	Compression Compression
	NoLchown    bool
}

type TempArchive

type TempArchive struct {
	*os.File
	Size int64 // Pre-computed from Stat().Size() as a convenience
}

func NewTempArchive

func NewTempArchive(src Archive, dir string) (*TempArchive, error)

NewTempArchive reads the content of src into a temporary file, and returns the contents of that file as an archive. The archive can only be read once - as soon as reading completes, the file will be deleted.

func (*TempArchive) Read

func (archive *TempArchive) Read(data []byte) (int, error)

Jump to

Keyboard shortcuts

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