Documentation ¶
Index ¶
- Variables
- type Archiver
- type Bz2
- type Compressor
- type Decompressor
- type Extractor
- type File
- type FileCompressor
- type FileInfo
- type Gz
- type Lz4
- type Matcher
- type Rar
- func (r *Rar) Close() error
- func (r *Rar) Extract(source, target, destination string) error
- func (*Rar) Match(file *os.File) (bool, error)
- func (r *Rar) Open(in io.Reader, size int64) error
- func (r *Rar) OpenFile(filename string) error
- func (r *Rar) Read() (File, error)
- func (r *Rar) String() string
- func (r *Rar) Unarchive(source, destination string) error
- func (r *Rar) Walk(archive string, walkFn WalkFunc) error
- type ReadFakeCloser
- type Reader
- type Snappy
- type Tar
- func (t *Tar) Archive(sources []string, destination string) error
- func (t *Tar) Close() error
- func (t *Tar) Create(out io.Writer) error
- func (t *Tar) Extract(source, target, destination string) error
- func (*Tar) Match(file *os.File) (bool, error)
- func (t *Tar) Open(in io.Reader, size int64) error
- func (t *Tar) Read() (File, error)
- func (t *Tar) String() string
- func (t *Tar) Unarchive(source, destination string) error
- func (t *Tar) Walk(archive string, walkFn WalkFunc) error
- func (t *Tar) Write(f File) error
- type TarBz2
- func (tbz2 *TarBz2) Archive(sources []string, destination string) error
- func (tbz2 *TarBz2) Create(out io.Writer) error
- func (tbz2 *TarBz2) Extract(source, target, destination string) error
- func (tbz2 *TarBz2) Open(in io.Reader, size int64) error
- func (tbz2 *TarBz2) String() string
- func (tbz2 *TarBz2) Unarchive(source, destination string) error
- func (tbz2 *TarBz2) Walk(archive string, walkFn WalkFunc) error
- type TarGz
- func (tgz *TarGz) Archive(sources []string, destination string) error
- func (tgz *TarGz) Create(out io.Writer) error
- func (tgz *TarGz) Extract(source, target, destination string) error
- func (tgz *TarGz) Open(in io.Reader, size int64) error
- func (tgz *TarGz) String() string
- func (tgz *TarGz) Unarchive(source, destination string) error
- func (tgz *TarGz) Walk(archive string, walkFn WalkFunc) error
- type TarLz4
- func (tlz4 *TarLz4) Archive(sources []string, destination string) error
- func (tlz4 *TarLz4) Create(out io.Writer) error
- func (tlz4 *TarLz4) Extract(source, target, destination string) error
- func (tlz4 *TarLz4) Open(in io.Reader, size int64) error
- func (tlz4 *TarLz4) String() string
- func (tlz4 *TarLz4) Unarchive(source, destination string) error
- func (tlz4 *TarLz4) Walk(archive string, walkFn WalkFunc) error
- type TarSz
- func (tsz *TarSz) Archive(sources []string, destination string) error
- func (tsz *TarSz) Create(out io.Writer) error
- func (tsz *TarSz) Extract(source, target, destination string) error
- func (tsz *TarSz) Open(in io.Reader, size int64) error
- func (tsz *TarSz) String() string
- func (tsz *TarSz) Unarchive(source, destination string) error
- func (tsz *TarSz) Walk(archive string, walkFn WalkFunc) error
- type TarXz
- func (txz *TarXz) Archive(sources []string, destination string) error
- func (txz *TarXz) Create(out io.Writer) error
- func (txz *TarXz) Extract(source, target, destination string) error
- func (txz *TarXz) Open(in io.Reader, size int64) error
- func (txz *TarXz) String() string
- func (txz *TarXz) Unarchive(source, destination string) error
- func (txz *TarXz) Walk(archive string, walkFn WalkFunc) error
- type Unarchiver
- type WalkFunc
- type Walker
- type Writer
- type Xz
- type Zip
- func (z *Zip) Archive(sources []string, destination string) error
- func (z *Zip) Close() error
- func (z *Zip) Create(out io.Writer) error
- func (z *Zip) Extract(source, target, destination string) error
- func (*Zip) Match(file *os.File) (bool, error)
- func (z *Zip) Open(in io.Reader, size int64) error
- func (z *Zip) Read() (File, error)
- func (z *Zip) String() string
- func (z *Zip) Unarchive(source, destination string) error
- func (z *Zip) Walk(archive string, walkFn WalkFunc) error
- func (z *Zip) Write(f File) error
Constants ¶
This section is empty.
Variables ¶
var DefaultRar = &Rar{ MkdirAll: true, }
DefaultRar is a convenient archiver ready to use.
var DefaultTar = &Tar{ MkdirAll: true, }
DefaultTar is a convenient archiver ready to use.
var DefaultTarBz2 = &TarBz2{ CompressionLevel: bzip2.DefaultCompression, Tar: DefaultTar, }
DefaultTarBz2 is a convenient archiver ready to use.
var DefaultTarGz = &TarGz{ CompressionLevel: gzip.DefaultCompression, Tar: DefaultTar, }
DefaultTarGz is a convenient archiver ready to use.
var DefaultTarLz4 = &TarLz4{ CompressionLevel: 9, Tar: DefaultTar, }
DefaultTarLz4 is a convenient archiver ready to use.
var DefaultTarSz = &TarSz{ Tar: DefaultTar, }
DefaultTarSz is a convenient archiver ready to use.
var DefaultTarXz = &TarXz{ Tar: DefaultTar, }
DefaultTarXz is a convenient archiver ready to use.
var DefaultZip = &Zip{ CompressionLevel: flate.DefaultCompression, MkdirAll: true, SelectiveCompression: true, }
DefaultZip is a convenient archiver ready to use.
var ErrStopWalk = fmt.Errorf("walk stopped")
ErrStopWalk signals Walk to break without error.
Functions ¶
This section is empty.
Types ¶
type Archiver ¶
Archiver is a type that can create an archive file from a list of source file names.
type Bz2 ¶
type Bz2 struct {
CompressionLevel int
}
Bz2 facilitates bzip2 compression.
func (*Bz2) Decompress ¶
Decompress reads in, decompresses it, and writes it to out.
type Compressor ¶
type Compressor interface { Compress(in io.Reader, out io.Writer) error CheckExt(filename string) error }
Compressor compresses to out what it reads from in. It also ensures a compatible or matching file extension.
type Decompressor ¶
Decompressor decompresses to out what it reads from in.
type Extractor ¶
Extractor can extract a specific file from a source archive to a specific destination folder on disk.
type File ¶
type File struct { os.FileInfo // The original header info; depends on // type of archive -- could be nil, too. Header interface{} // Allow the file contents to be read (and closed) io.ReadCloser }
File provides methods for accessing information about or contents of a file within an archive.
type FileCompressor ¶
type FileCompressor struct { Compressor Decompressor OverwriteExisting bool }
FileCompressor can compress and decompress single files.
func (FileCompressor) CompressFile ¶
func (fc FileCompressor) CompressFile(source, destination string) error
CompressFile reads the source file and compresses it to destination. The destination must have a matching extension.
func (FileCompressor) DecompressFile ¶
func (fc FileCompressor) DecompressFile(source, destination string) error
DecompressFile reads the source file and decompresses it to destination.
type FileInfo ¶
FileInfo is an os.FileInfo but optionally with a custom name, useful if dealing with files that are not actual files on disk, or which have a different name in an archive than on disk.
type Gz ¶
type Gz struct {
CompressionLevel int
}
Gz facilitates gzip compression.
func (*Gz) Decompress ¶
Decompress reads in, decompresses it, and writes it to out.
type Lz4 ¶
type Lz4 struct {
CompressionLevel int
}
Lz4 facilitates LZ4 compression.
func (*Lz4) Decompress ¶
Decompress reads in, decompresses it, and writes it to out.
type Matcher ¶
Matcher is a type that can return whether the given file appears to match the implementation's format. Implementations should return the file's read position to where it was when the method was called.
type Rar ¶
type Rar struct { // Whether to overwrite existing files; if false, // an error is returned if the file exists. OverwriteExisting bool // Whether to make all the directories necessary // to create a rar archive in the desired path. MkdirAll bool // A single top-level folder can be implicitly // created by the Unarchive method if the files // to be extracted from the archive do not all // have a common root. This roughly mimics the // behavior of archival tools integrated into OS // file browsers which create a subfolder to // avoid unexpectedly littering the destination // folder with potentially many files, causing a // problematic cleanup/organization situation. // This feature is available for both creation // and extraction of archives, but may be slightly // inefficient with lots and lots of files, // especially on extraction. ImplicitTopLevelFolder bool // If true, errors encountered during reading // or writing a single file will be logged and // the operation will continue on remaining files. ContinueOnError bool // The password to open archives (optional). Password string // contains filtered or unexported fields }
Rar provides facilities for reading RAR archives. See https://www.rarlab.com/technote.htm.
func (*Rar) Extract ¶
Extract extracts a single file from the rar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*Rar) Match ¶
Match returns true if the format of file matches this type's format. It should not affect reader position.
func (*Rar) OpenFile ¶
OpenFile opens filename for reading. This method supports multi-volume archives, whereas Open does not (but Open supports any stream, not just files).
func (*Rar) Read ¶
Read reads the next file from t, which must have already been opened for reading. If there are no more files, the error is io.EOF. The File must be closed when finished reading from it.
type ReadFakeCloser ¶
ReadFakeCloser is an io.Reader that has a no-op close method to satisfy the io.ReadCloser interface.
type Snappy ¶
type Snappy struct{}
Snappy facilitates Snappy compression.
func (*Snappy) Decompress ¶
Decompress reads in, decompresses it, and writes it to out.
type Tar ¶
type Tar struct { // Whether to overwrite existing files; if false, // an error is returned if the file exists. OverwriteExisting bool // Whether to make all the directories necessary // to create a tar archive in the desired path. MkdirAll bool // A single top-level folder can be implicitly // created by the Archive or Unarchive methods // if the files to be added to the archive // or the files to be extracted from the archive // do not all have a common root. This roughly // mimics the behavior of archival tools integrated // into OS file browsers which create a subfolder // to avoid unexpectedly littering the destination // folder with potentially many files, causing a // problematic cleanup/organization situation. // This feature is available for both creation // and extraction of archives, but may be slightly // inefficient with lots and lots of files, // especially on extraction. ImplicitTopLevelFolder bool // If true, errors encountered during reading // or writing a single file will be logged and // the operation will continue on remaining files. ContinueOnError bool // contains filtered or unexported fields }
Tar provides facilities for operating TAR archives. See http://www.gnu.org/software/tar/manual/html_node/Standard.html.
func (*Tar) Archive ¶
Archive creates a tarball file at destination containing the files listed in sources. The destination must end with ".tar". File paths can be those of regular files or directories; directories will be recursively added.
func (*Tar) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*Tar) Match ¶
Match returns true if the format of file matches this type's format. It should not affect reader position.
func (*Tar) Read ¶
Read reads the next file from t, which must have already been opened for reading. If there are no more files, the error is io.EOF. The File must be closed when finished reading from it.
func (*Tar) Unarchive ¶
Unarchive unpacks the .tar file at source to destination. Destination will be treated as a folder name.
type TarBz2 ¶
TarBz2 facilitates bzip2 compression (https://github.com/dsnet/compress/blob/master/doc/bzip2-format.pdf) of tarball archives.
func (*TarBz2) Archive ¶
Archive creates a compressed tar file at destination containing the files listed in sources. The destination must end with ".tar.bz2" or ".tbz2". File paths can be those of regular files or directories; directories will be recursively added.
func (*TarBz2) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*TarBz2) Open ¶
Open opens t for reading a compressed archive from in. The size parameter is not used.
type TarGz ¶
type TarGz struct { *Tar // The compression level to use, as described // in the compress/gzip package. CompressionLevel int }
TarGz facilitates gzip compression (RFC 1952) of tarball archives.
func (*TarGz) Archive ¶
Archive creates a compressed tar file at destination containing the files listed in sources. The destination must end with ".tar.gz" or ".tgz". File paths can be those of regular files or directories; directories will be recursively added.
func (*TarGz) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*TarGz) Open ¶
Open opens t for reading a compressed archive from in. The size parameter is not used.
type TarLz4 ¶
type TarLz4 struct { *Tar // The compression level to use when writing. // Minimum 0 (fast compression), maximum 12 // (most space savings). CompressionLevel int }
TarLz4 facilitates lz4 compression (https://github.com/lz4/lz4/tree/master/doc) of tarball archives.
func (*TarLz4) Archive ¶
Archive creates a compressed tar file at destination containing the files listed in sources. The destination must end with ".tar.lz4" or ".tlz4". File paths can be those of regular files or directories; directories will be recursively added.
func (*TarLz4) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*TarLz4) Open ¶
Open opens t for reading a compressed archive from in. The size parameter is not used.
type TarSz ¶
type TarSz struct {
*Tar
}
TarSz facilitates Snappy compression (https://github.com/google/snappy) of tarball archives.
func (*TarSz) Archive ¶
Archive creates a compressed tar file at destination containing the files listed in sources. The destination must end with ".tar.sz" or ".tsz". File paths can be those of regular files or directories; directories will be recursively added.
func (*TarSz) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*TarSz) Open ¶
Open opens t for reading a compressed archive from in. The size parameter is not used.
type TarXz ¶
type TarXz struct {
*Tar
}
TarXz facilitates xz compression (https://tukaani.org/xz/format.html) of tarball archives.
func (*TarXz) Archive ¶
Archive creates a compressed tar file at destination containing the files listed in sources. The destination must end with ".tar.gz" or ".txz". File paths can be those of regular files or directories; directories will be recursively added.
func (*TarXz) Extract ¶
Extract extracts a single file from the tar archive. If the target is a directory, the entire folder will be extracted into destination.
func (*TarXz) Open ¶
Open opens t for reading a compressed archive from in. The size parameter is not used.
type Unarchiver ¶
Unarchiver is a type that can extract archive files into a folder.
type WalkFunc ¶
WalkFunc is called at each item visited by Walk. If an error is returned, the walk may continue if the Walker is configured to continue on error. The sole exception is the error value ErrStopWalk, which stops the walk without an actual error.
type Walker ¶
Walker can walk an archive file and return information about each item in the archive.
type Xz ¶
type Xz struct{}
Xz facilitates XZ compression.
func (*Xz) Decompress ¶
Decompress reads in, decompresses it, and writes it to out.
type Zip ¶
type Zip struct { // The compression level to use, as described // in the compress/flate package. CompressionLevel int // Whether to overwrite existing files; if false, // an error is returned if the file exists. OverwriteExisting bool // Whether to make all the directories necessary // to create a zip archive in the desired path. MkdirAll bool // If enabled, selective compression will only // compress files which are not already in a // compressed format; this is decided based // simply on file extension. SelectiveCompression bool // A single top-level folder can be implicitly // created by the Archive or Unarchive methods // if the files to be added to the archive // or the files to be extracted from the archive // do not all have a common root. This roughly // mimics the behavior of archival tools integrated // into OS file browsers which create a subfolder // to avoid unexpectedly littering the destination // folder with potentially many files, causing a // problematic cleanup/organization situation. // This feature is available for both creation // and extraction of archives, but may be slightly // inefficient with lots and lots of files, // especially on extraction. ImplicitTopLevelFolder bool // If true, errors encountered during reading // or writing a single file will be logged and // the operation will continue on remaining files. ContinueOnError bool // contains filtered or unexported fields }
Zip provides facilities for operating ZIP archives. See https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT.
func (*Zip) Archive ¶
Archive creates a .zip file at destination containing the files listed in sources. The destination must end with ".zip". File paths can be those of regular files or directories. Regular files are stored at the 'root' of the archive, and directories are recursively added.
func (*Zip) Extract ¶
Extract extracts a single file from the zip archive. If the target is a directory, the entire folder will be extracted into destination.
func (*Zip) Match ¶
Match returns true if the format of file matches this type's format. It should not affect reader position.
func (*Zip) Open ¶
Open opens z for reading an archive from in, which is expected to have the given size and which must be an io.ReaderAt.
func (*Zip) Read ¶
Read reads the next file from z, which must have already been opened for reading. If there are no more files, the error is io.EOF. The File must be closed when finished reading from it.
func (*Zip) Unarchive ¶
Unarchive unpacks the .zip file at source to destination. Destination will be treated as a folder name.