Documentation ¶
Overview ¶
Package archive implements functions for decoding and extracting archives such as ZIP, tar.gz or RAR.
Index ¶
- Variables
- func Basename(path string) string
- func CreateDir(path string) error
- func Extract(a Archive, path string, progressChan chan progress.Progress, ...) error
- func HasSingleRoot(a Archive) bool
- func IsCanceled(err error) bool
- func RegisterFormat(name string, matches func(filename string, r io.Reader) bool, ...)
- type Archive
- type File
- type FileHeader
Constants ¶
This section is empty.
Variables ¶
var ErrCanceled = errors.New("the process was canceled by user request")
ErrCanceled is the error returned by Extract, when the process was canceled by the user
var ErrUnknownFormat = errors.New("archive: unknown format")
ErrUnknownFormat indicates an unknown archive format.
Functions ¶
func Basename ¶
Basename returns the base name for a given file path, without a file extension or the path to the containing directory. e.g. Basename("/home/user/test.txt") returns "test" and Basename("user/test.tar.gz") returns "test" In general only single file extensions are supported, but this implementation contains a special case to remove the optional ".tar.*" suffix.
func CreateDir ¶
CreateDir creats the specified directory along with any necessary parent directories with 0777 permissions (before umask).
func Extract ¶
func Extract(a Archive, path string, progressChan chan progress.Progress, shouldCancel func() bool) error
Extract extracts the Archive a to the specified path and reports progress to the supplied progressChan. If the supplied shouldCancel func returns true, the extraction will get canceled as soon as possible and return ErrCanceled. Callers should check using IsCanceled.
func HasSingleRoot ¶
HasSingleRoot returns true, if the archive contains only a single file/directory at the root of the archive. e.g. [/README, /a.bin] -> false, [/a/README, /a/a.bin] -> true. WARNING: This iterates the archive from the beginning and resets the current position!
func IsCanceled ¶ added in v0.2.1
IsCanceled returns true if err represents that process was canceled by the user
func RegisterFormat ¶
func RegisterFormat(name string, matches func(filename string, r io.Reader) bool, decode func(*os.File) (Archive, error))
RegisterFormat registers an archive format for use by Decode. Name is the name of the format, like "zip", "tar" or "rar". Matches is a function that determines if the format is capable of reading the archive from reader r. Decode is the function that decodes the archive.
Types ¶
type Archive ¶
type Archive interface { // Basename returns the base name of the archive file, without file extension or path. Basename() string // NumFiles returns the total number of files in the archive NumFiles() int // Next returns the next file in the archive. err == io.EOF on end of archive. Next() (File, error) // Reset resets the current position to the start of the archive. Reset() error }
Archive represent an archive and provides methods for iterating through its files.
type File ¶
type File interface { FileHeader io.ReadCloser }
File is equivalent to FileHeader but also provides a io.ReadCloser for accessing the file's content.
type FileHeader ¶
type FileHeader interface { Path() string // Path returns the file path in the archive. Only forward slashes are allowed as separators. Mode() os.FileMode }
FileHeader contains basic information about a file in the archive, such as Name, Path, and FileMode.
Directories ¶
Path | Synopsis |
---|---|
Package rar provides support for reading and extracting ZIP archives.
|
Package rar provides support for reading and extracting ZIP archives. |
Package tar provides support for reading and extracting ZIP archives.
|
Package tar provides support for reading and extracting ZIP archives. |
Package zip provides support for reading and extracting ZIP archives.
|
Package zip provides support for reading and extracting ZIP archives. |