Documentation ¶
Overview ¶
Package archive contains methods for extracting file(s) from arbitrary archive types. The archive types supported are:
- tar
- tar.gz
- tar.xz
- tar.bz2
- zip
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Archive ¶
type Archive interface { // Next returns the next file in the archive, or returns // io.EOF if there are no more files. Next() (*Header, io.ReadCloser, error) }
Archive is an interface for interacting with files inside of an archive
type CompressedReader ¶
type CompressedReader interface { // Open returns a reader for the compressed file. // This only returns a io.ReadCloser because it should only contain a single file Open(ctx context.Context, r io.Reader) (io.ReadCloser, error) }
CompressedReader is the interface for a reader that can read a compressed file.
type ExtractOptionFunc ¶
type ExtractOptionFunc func(*ExtractOptions) error
ExtractOptionFunc is an option function that mutates an ExtractOptions struct.
func WithFilePath ¶
func WithFilePath(filePath string) ExtractOptionFunc
WithFilePath is an ExtractOptionFunc that sets the file path to extract out of the provided archive.
func WithFilePathSelector ¶
func WithFilePathSelector(fn func(string) bool) ExtractOptionFunc
WithFilePathSelector is an ExtractOptionFunc that sets the file path selector function. See ExtractOptions.FilePathSelectorFunc for more details.
type ExtractOptions ¶
type ExtractOptions struct { // FilePath is the file path to extract out of the provided archive FilePath string // FilePathSelectorFunc is a function that can be used to select a file path // during extraction when there's a set criteria (or logic) that needs to be // ran to determine which file path to extract out of the archive. // // Note: When this function returns true, the file is returned. Multiple files // are not supported at this time. FilePathSelectorFunc func(string) bool }
ExtractOptions are the options for the Extract function.
type Extractor ¶
type Extractor interface { // Open returns a reader for the archive file Open(ctx context.Context, archiveName string, archive io.Reader) (Archive, error) // Close closes the reader returned by Open Close() error }
Extractor is the interface for creating a io.ReadCloser from an archive.
type Header ¶
type Header struct { // Name is the name of the file entry Name string // Mode is the mode of the file entry Mode int64 // Size is the size of the file entry Size int64 // Type is the type of entry this is // (file, directory, etc) Type HeaderType }
Header is a generic struct containing information about a file in an archive.
type HeaderType ¶
type HeaderType string
HeaderType is the type of entry a Header is for in an archive
const ( // HeaderTypeFile is a file entry HeaderTypeFile HeaderType = "file" // HeaderTypeDirectory is a directory entry HeaderTypeDirectory HeaderType = "directory" )