tz

package
v0.0.0-...-38f917a Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tz enables you to transparently read or write TAR.GZ compressed archives and the files inside them.

Index

Constants

This section is empty.

Variables

View Source
var Verbose = true

Switcher of printing trace information when pack and extract.

Functions

func ExtractTo

func ExtractTo(srcPath, destPath string, entries ...string) (err error)

ExtractTo extracts given archive or the given files to the specified destination.

func PackTo

func PackTo(srcPath, destPath string, includeDir ...bool) error

PackTo packs the whole archive to the specified destination. Call Flush() will automatically call this in the end.

func PackToFunc

func PackToFunc(srcPath, destPath string, fn func(fullName string, fi os.FileInfo) error, includeDir ...bool) error

PackToFunc packs the complete archive to the specified destination. It accepts a function as a middleware for custom operations.

Types

type File

type File struct {
	*tar.Header
	// contains filtered or unexported fields
}

A File represents a file or directory entry in archive.

type ReadCloser

type ReadCloser struct {
	File []*tar.Header
	// contains filtered or unexported fields
}

A ReadCloser represents a caller closable file reader.

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close closes the tar.gz file, rendering it unusable for I/O.

type StreamArchive

type StreamArchive struct {
	*tar.Writer
	// contains filtered or unexported fields
}

A StreamArchive represents a streamable archive.

func NewStreamArachive

func NewStreamArachive(w io.Writer) *StreamArchive

NewStreamArachive returns a new streamable archive with given io.Writer. It's caller's responsibility to close io.Writer and streamer after operation.

func (*StreamArchive) Close

func (s *StreamArchive) Close() (err error)

func (*StreamArchive) StreamFile

func (s *StreamArchive) StreamFile(relPath string, fi os.FileInfo, data []byte) error

StreamFile streams a file or directory entry into StreamArchive.

func (*StreamArchive) StreamReader

func (s *StreamArchive) StreamReader(relPath string, fi os.FileInfo, r io.Reader) (err error)

StreamReader streams data from io.Reader to StreamArchive.

type TzArchive

type TzArchive struct {
	*ReadCloser
	FileName   string
	NumFiles   int
	Flag       int
	Permission os.FileMode
	// contains filtered or unexported fields
}

A TzArchive represents a file archive, compressed with Tar and Gzip.

func Create

func Create(fileName string) (*TzArchive, error)

Create creates the named tar.gz file, truncating it if it already exists. If successful, methods on the returned TzArchive can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

func New

func New(w io.Writer) *TzArchive

New accepts a variable that implemented interface io.Writer for write-only purpose operations.

func Open

func Open(fileName string) (*TzArchive, error)

Open opens the named tar.gz file for reading. If successful, methods on the returned TzArchive can be used for reading; the associated file descriptor has mode O_RDONLY. If there is an error, it will be of type *PathError.

func OpenFile

func OpenFile(fileName string, flag int, perm os.FileMode) (*TzArchive, error)

OpenFile is the generalized open call; most users will use Open instead. It opens the named tar.gz file with specified flag (O_RDONLY etc.) if applicable. If successful, methods on the returned TzArchive can be used for I/O. If there is an error, it will be of type *PathError.

func (*TzArchive) AddDir

func (tz *TzArchive) AddDir(dirPath, absPath string) error

AddDir adds a directory and subdirectories entries to TzArchive.

func (*TzArchive) AddEmptyDir

func (tz *TzArchive) AddEmptyDir(dirPath string) bool

AddEmptyDir adds a raw directory entry to TzArchive, it returns false if same directory enry already existed.

func (*TzArchive) AddFile

func (tz *TzArchive) AddFile(fileName, absPath string) error

AddFile adds a file entry to TzArchive.

func (*TzArchive) Close

func (z *TzArchive) Close() (err error)

Close opens or creates archive and save changes.

func (*TzArchive) DeleteIndex

func (tz *TzArchive) DeleteIndex(idx int) error

DeleteIndex deletes an entry in the archive by its index.

func (*TzArchive) DeleteName

func (tz *TzArchive) DeleteName(name string) error

DeleteName deletes an entry in the archive by its name.

func (*TzArchive) ExtractTo

func (tz *TzArchive) ExtractTo(destPath string, entries ...string) (err error)

ExtractTo extracts the whole archive or the given files to the specified destination. Call Flush() to apply changes before this.

func (*TzArchive) ExtractToFunc

func (tz *TzArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error)

ExtractTo extracts the whole archive or the given files to the specified destination. It accepts a function as a middleware for custom operations.

func (*TzArchive) Flush

func (tz *TzArchive) Flush() (err error)

Flush saves changes to original zip file if any.

func (*TzArchive) List

func (tz *TzArchive) List(prefixes ...string) []string

List returns a string slice of files' name in TzArchive. Specify prefixes will be used as filters.

func (*TzArchive) Open

func (tz *TzArchive) Open(name string, flag int, perm os.FileMode) error

Open is the generalized open call; most users will use Open instead. It opens the named tar.gz file with specified flag (O_RDONLY etc.) if applicable. If successful, methods on the returned TzArchive can be used for I/O. If there is an error, it will be of type *PathError.

Jump to

Keyboard shortcuts

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