zip

package
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package zip enables you to transparently read or write ZIP 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 ExtractToFunc

func ExtractToFunc(srcPath, destPath string, fn cae.HookFunc, entries ...string) (err error)

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

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 {
	*zip.FileHeader
	// contains filtered or unexported fields
}

A File represents a file or directory entry in archive.

type StreamArchive

type StreamArchive struct {
	*zip.Writer
}

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) 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 ZipArchive

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

A ZipArchive represents a file archive, compressed with Zip.

func Create

func Create(name string) (*ZipArchive, error)

Create creates the named zip file, truncating it if it already exists. If successful, methods on the returned ZipArchive 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) *ZipArchive

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

func Open

func Open(name string) (*ZipArchive, error)

Open opens the named zip file for reading. If successful, methods on the returned ZipArchive 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(name string, flag int, perm os.FileMode) (*ZipArchive, error)

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

func (*ZipArchive) AddDir

func (z *ZipArchive) AddDir(dirPath, absPath string) error

AddDir adds a directory and subdirectories entries to ZipArchive.

func (*ZipArchive) AddEmptyDir

func (z *ZipArchive) AddEmptyDir(dirPath string) bool

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

func (*ZipArchive) AddFile

func (z *ZipArchive) AddFile(fileName, absPath string) error

AddFile adds a file entry to ZipArchive.

func (*ZipArchive) Close

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

Close opens or creates archive and save changes.

func (*ZipArchive) DeleteIndex

func (z *ZipArchive) DeleteIndex(idx int) error

DeleteIndex deletes an entry in the archive by its index.

func (*ZipArchive) DeleteName

func (z *ZipArchive) DeleteName(name string) error

DeleteName deletes an entry in the archive by its name.

func (*ZipArchive) ExtractTo

func (z *ZipArchive) 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 (*ZipArchive) ExtractToFunc

func (z *ZipArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error)

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

func (*ZipArchive) Flush

func (z *ZipArchive) Flush() error

Flush saves changes to original zip file if any.

func (*ZipArchive) List

func (z *ZipArchive) List(prefixes ...string) []string

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

func (*ZipArchive) Open

func (z *ZipArchive) Open(name string, flag int, perm os.FileMode) error

OpenFile is the generalized open call; most users will use Open instead. It opens the named zip file with specified flag (O_RDONLY etc.) if applicable. If successful, methods on the returned ZipArchive 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