Documentation ¶
Overview ¶
Package zip enables you to transparently read or write ZIP compressed archives and the files inside them.
Index ¶
- Variables
- 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 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(index 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 func(fullName string, fi os.FileInfo) error, ...) (err error)
- func (z *ZipArchive) Flush() error
- func (z *ZipArchive) ListName(prefixes ...string) []string
- func (z *ZipArchive) Open(fileName string, flag int, perm os.FileMode) error
Constants ¶
This section is empty.
Variables ¶
var Verbose = true
Functions ¶
Types ¶
type File ¶
type File struct { *zip.FileHeader // contains filtered or unexported fields }
File represents a file in archive.
type ZipArchive ¶
type ZipArchive struct { *zip.ReadCloser FileName string Comment string NumFiles int Flag int Permission os.FileMode // contains filtered or unexported fields }
ZipArchive represents a file archive, compressed with Zip.
func Create ¶
func Create(fileName string) (zip *ZipArchive, err 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) (zip *ZipArchive)
New accepts a variable that implemented interface io.Writer for write-only purpose operations.
func Open ¶
func Open(fileName string) (zip *ZipArchive, err 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
AddFile adds a directory and subdirectories entries to ZipArchive,
func (*ZipArchive) AddEmptyDir ¶
func (z *ZipArchive) AddEmptyDir(dirPath string) bool
AddEmptyDir adds a directory entry to ZipArchive, it returns false when directory 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 opened or created archive and save changes.
func (*ZipArchive) DeleteIndex ¶
func (z *ZipArchive) DeleteIndex(index int) error
DeleteIndex deletes an entry in the archive using its index.
func (*ZipArchive) DeleteName ¶
func (z *ZipArchive) DeleteName(name string) error
DeleteName deletes an entry in the archive using its name.
func (*ZipArchive) ExtractTo ¶
func (z *ZipArchive) ExtractTo(destPath string, entries ...string) (err error)
ExtractTo extracts the complete 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 func(fullName string, fi os.FileInfo) error, entries ...string) (err error)
ExtractTo extracts the complete 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) ListName ¶
func (z *ZipArchive) ListName(prefixes ...string) []string
ListName returns a string slice of files' name in ZipArchive.
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.