Documentation ¶
Overview ¶
Extract implements the extraction of files from various file archive or compression formats.
The entrypoint for the package is ExtractFile which is meant to call the appropriate handlers for the file at the given path based on the filename extensions. OpenArchive may also be used. The resulting Archive struct has methods which handle common archive types.
Index ¶
- func ExtractFile(filePath string, filterStrings []string, overwrite bool) error
- type Archive
- func (a *Archive) Close()
- func (a *Archive) Un7z(outputDir string, filters util.FilterSet, overwrite bool) []string
- func (a *Archive) Unbzip2() error
- func (a *Archive) Ungzip() error
- func (a *Archive) Untar(outputDir string, filters util.FilterSet, overwrite bool) []string
- func (a *Archive) Unxz() error
- func (a *Archive) Unzip(outputDir string, filters util.FilterSet, overwrite bool) []string
- func (a *Archive) WriteSingleton(outputPath string, mode fs.FileMode, overwrite bool) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractFile ¶
ExtractFile extracts the contents of the file archive at the given filePath. The filterStrings argument accepts a slice of strings (which will be compiled into regexp.Regexp objects) to filter what will be extracted from the file archive.
Types ¶
type Archive ¶
type Archive struct { Path string // full path to the archive file PathNoExt string // full path to the archive file with any recognized filename extensions removed FileHandle *os.File // file handle for the archive file FileStats fs.FileInfo // file statistics for the archive file StreamHandle io.ReadCloser // handle for optional decompression reader }
Archive is a handle for optionally-compressed file archives which contain one or more files.
func OpenArchive ¶
OpenArchive opens the archive file at the given path and returns a handle suitable for file extraction operations on that archive
func (*Archive) Close ¶
func (a *Archive) Close()
Close handles closing the resources contained in an Archive handle
func (*Archive) Un7z ¶ added in v0.4.0
Un7z extracts the Archive's contents into the given output directory using the a sevenzip file reader. If there are any filters in the given FilterSet then files are only extracted if they match one of the given filters. If the files to be created conflict with existing files in the outputDir then extraction will stop unless the overwrite argument is set to true.
func (*Archive) Unbzip2 ¶ added in v0.3.2
Unbzip2 enables bzip2 decompression of the Archive data. It creates a bzip2 stream reader for Archive.FileHandle on Archive.StreamHandle. Any errors creating the reader will be returned.
func (*Archive) Ungzip ¶ added in v0.3.2
Ungzip enables gzip decompression of the Archive data. It creates a gzip stream reader for Archive.FileHandle on Archive.StreamHandle. Any errors creating the reader will be returned.
func (*Archive) Untar ¶
Untar extracts the Archive's contents into the given output directory using a tar file reader. If there are any filters in the given FilterSet then files are only extracted if they match one of the given filters. If the files to be created conflict with existing files in the outputDir then extraction will stop unless the overwrite argument is set to true.
func (*Archive) Unxz ¶
Unxz enables xz decompression of the Archive data. It creates an xz stream reader for Archive.FileHandle on Archive.StreamHandle. Any errors creating the reader will be returned.
func (*Archive) Unzip ¶
Unzip extracts the Archive's contents into the given output directory using the a zip file reader. If there are any filters in the given FilterSet then files are only extracted if they match one of the given filters. If the files to be created conflict with existing files in the outputDir then extraction will stop unless the overwrite argument is set to true.
func (*Archive) WriteSingleton ¶
WriteSingleton extracts the Archive's solitary file into the given output directory using io.Copy. This is typically applied when a single file is compressed with a utility like gzip. If the file to be written conflicts with an existing file in the outputDir then extraction will stop unless the overwrite argument is set to true.