Documentation ¶
Index ¶
- Constants
- Variables
- func Extract(path string, options ExtractOptions) error
- func ExtractFile(path string, file string, options ExtractFileOptions) error
- type Archive
- func (a *Archive) Close() error
- func (a *Archive) Extract(opts ExtractOptions) error
- func (a *Archive) ExtractBillyFS(filesystem billy.Filesystem, opts ExtractOptions) error
- func (a *Archive) ExtractFile(path string, opts ExtractFileOptions) error
- func (a *Archive) FileCount() int
- func (a *Archive) GetFile(path string) (*File, error)
- type ExtractFileOptions
- type ExtractOptions
- type File
- type Filesystem
- type Type
Constants ¶
const ( TarGzip Type = "tar.gz" TarBzip = "tar.bz2" TarXz = "tar.xz" Tar = "tar" Zip = "zip" )
Variables ¶
var ( ErrArchiveTypeNotSupported = errors.New("archive type not supported") ErrArchiveFileNotFound = errors.New("archive file not found") )
Functions ¶
func Extract ¶
func Extract(path string, options ExtractOptions) error
Extract opens an archive file and extracts the contents. It takes a path, and ExtractOptions for its parameters. The function returns an error, if any.
func ExtractFile ¶
func ExtractFile(path string, file string, options ExtractFileOptions) error
ExtractFile opens an archive file and extracts a specific file within the archive. It takes a path, a file path, and ExtractFileOptions for its parameters. The function returns an error, if any.
Types ¶
type Archive ¶
type Archive struct { // Type of Archive Type Type // Path of Archive file Path string // contains filtered or unexported fields }
func Open ¶
Open opens an archive file and returns an Archive struct. It takes a path to the archive file as its parameter. The function returns an Archive struct and an error, if any.
func OpenFS ¶
func OpenFS(filesystem Filesystem, path string) (*Archive, error)
OpenFS opens an archive file from a given fs.FS and returns an Archive struct. It takes fs.FS, and a path to the archive file as its parameters. The function returns an Archive struct and an error, if any.
func (*Archive) Extract ¶
func (a *Archive) Extract(opts ExtractOptions) error
Extract extracts the specified Archive to a specified directory. It takes ExtractOptions as its parameter The function returns an error, if any.
func (*Archive) ExtractBillyFS ¶
func (a *Archive) ExtractBillyFS(filesystem billy.Filesystem, opts ExtractOptions) error
ExtractBillyFS extracts the specified Archive into billy.Filesystem. It takes billy.Filesystem and ExtractOptions as its parameters. The function returns an error, if any.
func (*Archive) ExtractFile ¶
func (a *Archive) ExtractFile(path string, opts ExtractFileOptions) error
ExtractFile extracts a specified file from an archive to a specified directory. It takes a file path, and ExtractFileOptions as its parameters. The function returns an error, if any.
type ExtractFileOptions ¶
type ExtractFileOptions struct { // Whether to overwrite files if they already exist. Overwrite bool // Perms for output file, default is the permission in the Archive. Perms os.FileMode // Folder to extract Archive to. Folder string // Whether to preserve the file structure in the Archive or not. NotPreserveFileStructure bool }
ExtractFileOptions represents options for extracting an ArchiveFile
type ExtractOptions ¶
type ExtractOptions struct { // Whether to overwrite files if they already exist. Overwrite bool // Folder to extract Archive to. Folder string // Whether to preserve the file structure in the Archive or not. NotPreserveFileStructure bool // Optional regex filter for specific files. Filter *regexp.Regexp }
ExtractOptions represents options for extracting an Archive
type File ¶
type File struct { // Name of file (e.g "test.txt") FileName string // Path of file in archive (e.g "folder/test.txt") Path string // contains filtered or unexported fields }
File represents a file in an archive.
func (*File) Extract ¶
func (f *File) Extract(opts ExtractFileOptions) error
Extract extracts the specified File in the archive to a specified directory. It takes ExtractFileOptions as its parameter. The function returns an error, if any.
func (*File) ExtractBillyFS ¶
func (f *File) ExtractBillyFS(filesystem billy.Filesystem, opts ExtractFileOptions) error
ExtractBillyFS extracts the specified File in the archive into billy.Filesystem. It takes billy.Filesystem and ExtractFileOptions as its parameters. The function returns an error, if any.
type Filesystem ¶
type Filesystem struct {
// contains filtered or unexported fields
}
Filesystem represents a standard interface for filesystems. Currently, supports fs.FS and billy.Filesystem.
func WrapBillyFS ¶
func WrapBillyFS(filesystem billy.Filesystem) Filesystem
WrapBillyFS wraps billy.Filesystem to the Filesystem interface. Returns Filesystem.
func WrapFS ¶
func WrapFS(filesystem fs.FS) Filesystem
WrapFS wraps fs.FS to the Filesystem interface. Returns Filesystem.
func WrapPath ¶
func WrapPath(path string) Filesystem
WrapPath wraps a path to the Filesystem interface. Returns Filesystem.