Documentation ¶
Overview ¶
Package zip enables you to transparently read or write ZIP compressed archives and the files inside them.
Index ¶
- Variables
- func ExtractTo(srcPath, destPath string, entries ...string) (err error)
- func ExtractToFunc(srcPath, destPath string, fn cae.HookFunc, entries ...string) (err error)
- func PackTo(srcPath, destPath string, includeDir ...bool) error
- func PackToFunc(srcPath, destPath string, fn func(fullName string, fi os.FileInfo) error, ...) error
- type File
- type StreamArchive
- type ZipArchive
- func (z *ZipArchive) AddDir(dirPath, absPath string) error
- func (z *ZipArchive) AddEmptyDir(dirPath string) bool
- func (z *ZipArchive) AddFile(fileName, absPath string) error
- func (z *ZipArchive) Close() (err error)
- func (z *ZipArchive) DeleteIndex(idx int) error
- func (z *ZipArchive) DeleteName(name string) error
- func (z *ZipArchive) ExtractTo(destPath string, entries ...string) (err error)
- func (z *ZipArchive) ExtractToFunc(destPath string, fn cae.HookFunc, entries ...string) (err error)
- func (z *ZipArchive) Flush() error
- func (z *ZipArchive) List(prefixes ...string) []string
- func (z *ZipArchive) Open(name string, flag int, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var Verbose = true
Switcher of printing trace information when pack and extract.
Functions ¶
func ExtractToFunc ¶
ExtractToFunc extracts the whole archive or the given files 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 ¶
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 ¶
StreamFile streams a file or directory entry into StreamArchive.
func (*StreamArchive) StreamReader ¶
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 ¶
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 ¶
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 ¶
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.