archive

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2017 License: BSD-3-Clause Imports: 9 Imported by: 4

Documentation

Overview

Package archive implements functions for decoding and extracting archives such as ZIP, tar.gz or RAR.

Index

Constants

This section is empty.

Variables

View Source
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

View Source
var ErrUnknownFormat = errors.New("archive: unknown format")

ErrUnknownFormat indicates an unknown archive format.

Functions

func Basename

func Basename(path string) string

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

func CreateDir(path string) error

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

func HasSingleRoot(a Archive) bool

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

func IsCanceled(err error) bool

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.

func Decode

func Decode(file *os.File) (Archive, string, error)

Decode decodes an archive in a registered format. The string returned is the format name used during format registration. Format registration is typically done by an init function in the codec- specific package.

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.

Jump to

Keyboard shortcuts

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