archiver

package
v0.0.0-...-6bdf688 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

package archive is heavily inspired by https://github.com/mholt/archiver/blob/master/tar.go (License MIT) just with an addition to archive directly to a given writer and removal of unused functionality

Index

Constants

This section is empty.

Variables

View Source
var DefaultTar = NewTar()

DefaultTar is a default instance that is conveniently ready to use.

View Source
var ErrFormatNotRecognized = fmt.Errorf("format not recognized")

ErrFormatNotRecognized is an error that will be returned if the file is not a valid archive format.

View Source
var ErrStopWalk = fmt.Errorf("walk stopped")

ErrStopWalk signals Walk to break without error.

Functions

func Unarchive

func Unarchive(source, destination string) error

Unarchive - unarchive tar

Types

type File

type File struct {
	os.FileInfo

	// The original header info; depends on
	// type of archive -- could be nil, too.
	Header interface{}

	// Allow the file contents to be read (and closed)
	io.ReadCloser
}

File provides methods for accessing information about or contents of a file within an archive.

type FileInfo

type FileInfo struct {
	os.FileInfo
	CustomName string
}

func (FileInfo) Name

func (fi FileInfo) Name() string

type ReadFakeCloser

type ReadFakeCloser struct {
	io.Reader
}

func (ReadFakeCloser) Close

func (rfc ReadFakeCloser) Close() error

Close implements io.Closer.

type Tar

type Tar struct {
	// Whether to overwrite existing files; if false,
	// an error is returned if the file exists.
	OverwriteExisting bool

	// Whether to make all the directories necessary
	// to create a tar archive in the desired path.
	MkdirAll bool

	// A single top-level folder can be implicitly
	// created by the Archive or Unarchive methods
	// if the files to be added to the archive
	// or the files to be extracted from the archive
	// do not all have a common root. This roughly
	// mimics the behavior of archival tools integrated
	// into OS file browsers which create a subfolder
	// to avoid unexpectedly littering the destination
	// folder with potentially many files, causing a
	// problematic cleanup/organization situation.
	// This feature is available for both creation
	// and extraction of archives, but may be slightly
	// inefficient with lots and lots of files,
	// especially on extraction.
	ImplicitTopLevelFolder bool

	// If true, errors encountered during reading
	// or writing a single file will be logged and
	// the operation will continue on remaining files.
	ContinueOnError bool
	// contains filtered or unexported fields
}

Tar provides facilities for operating TAR archives. See http://www.gnu.org/software/tar/manual/html_node/Standard.html.

func NewTar

func NewTar() *Tar

NewTar returns a new, default instance ready to be customized and used.

func (*Tar) Archive

func (t *Tar) Archive(sources []string, destination string) error

Archive creates a tarball file at destination containing the files listed in sources. The destination must end with ".tar". File paths can be those of regular files or directories; directories will be recursively added.

func (*Tar) ArchiveToStream

func (t *Tar) ArchiveToStream(output io.Writer, sources []string) error

func (*Tar) CheckExt

func (*Tar) CheckExt(filename string) error

CheckExt ensures the file extension matches the format.

func (*Tar) Close

func (t *Tar) Close() error

Close closes the tar archive(s) opened by Create and Open.

func (*Tar) Create

func (t *Tar) Create(out io.Writer) error

Create opens t for writing a tar archive to out.

func (*Tar) Open

func (t *Tar) Open(in io.Reader, size int64) error

Open opens t for reading an archive from in. The size parameter is not used.

func (*Tar) Read

func (t *Tar) Read() (File, error)

Read reads the next file from t, which must have already been opened for reading. If there are no more files, the error is io.EOF. The File must be closed when finished reading from it.

func (*Tar) Unarchive

func (t *Tar) Unarchive(source, destination string) error

Unarchive unpacks the .tar file at source to destination. Destination will be treated as a folder name.

func (*Tar) Walk

func (t *Tar) Walk(archive string, walkFn WalkFunc) error

Walk calls walkFn for each visited item in archive.

func (*Tar) Write

func (t *Tar) Write(f File) error

Write writes f to t, which must have been opened for writing first.

type WalkFunc

type WalkFunc func(f File) error

Jump to

Keyboard shortcuts

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