extract

package module
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 24 Imported by: 0

README

extract issues extract GoDoc

Introducing extract v2.0 - a simple utility and GO library to extract different archive types.


Features

Package extract attempts to make it simple to decompress the compatible archive formats.

The extract command can be ran with no flags to decompress all compatible archive bundles in the current directory in place. It can also be ran with the following flags:

-f FILE | --flag=FILE
to decomress a single bundle. This flag may be used more than once if there are multiple bundles.
-d DIR | --dest=DIR
Sets a destination directory for the archives to be extracted into. By default this is set to the current working directory.
-c INT | --count=INT
Sets the number of concurrent extractions that can take place. By default this is set to 4.
-h | --help
Displays the help text
--version
Displays the version of extract in use.

The extract tool now has the ability to run with concurrent extractions, by default 4. Previous versions of the tool ran in serial which was somewhat slow.

Supported formats

The following archive/compression types are supported by extract:

  • gzip
  • tar
  • zip
  • rar (without password)
  • bzip
  • More to be added...

GoDoc

See https://pkg.go.dev/github.com/Galzzly/extract


Install

GO

To install the binary directly into your $GOPATH/bin:

go get github.com/Galzzly/extract/cmd/extract

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddNewBar

func AddNewBar(p *mpb.Progress, file string, start time.Time) (b *mpb.Bar)

func ByFormat

func ByFormat(filename string) (interface{}, error)

Will return an new instance of the file format based on the magic numbers found in the file.

func CheckPath

func CheckPath(destination, filename string) (err error)

CheckPath confirms that the path provided has not been made to perform a traversal attack.

func DirFromFile

func DirFromFile(filename string) (dir string)

DirFromFile returns a directory based on the filename provided to the function.

func Extract

func Extract(fileList *[]string, destDir string, numC uint32) (err error)

func FileExists

func FileExists(filename string) bool

FileExists will check for the existence of a file provided to the function as filename

func GetFile

func GetFile(file string) (f *os.File, err error)

GetFile will return the open file ready for reading

func GetFileCType

func GetFileCType(out *os.File) (string, error)

GetFileCType is a simplistic way of pulling out the MIMI type of a file. Does not always pull out the type, and will instead replace with application/octet-stream. Particularly when the filie is smaller than 512 bytes. As such, this should not necessarily be relied upon.

func GetFileHeader

func GetFileHeader(file string, l uint32) ([]byte, error)

Return slice of bytes from file header

func GetFileName

func GetFileName(f string) string

GetFileName will strip the the file name to extract to by removing the suffix. e.g. filename.tar becomes filename

func GetFormat

func GetFormat(filename string) (interface{}, error)

GetFormat returns the format of the file

func GetHeader

func GetHeader(r io.Reader, l uint32) (in []byte, err error)

GetHeader will return the first l bytes of the file input r

func IsIllegalPathError

func IsIllegalPathError(err error) bool
func IsSymlink(fi os.FileInfo) bool

IsSymlink returns true if the file is a symlink.

func Mkdir

func Mkdir(path string, mode os.FileMode) error

Mkdir creates a directory at the destination path, along with any parent directories

func TopLevels

func TopLevels(paths []string) bool

TopLevels reads a slice of paths in, and returns true if there are multiple top-level directories.

func WriteFile

func WriteFile(destination string, in io.Reader, mode os.FileMode) (err error)

WriteFile writes a file to the destination path.

func WriteHardlink(destination, link string) (err error)

WriteHardlink creates the hard link at the destination location.

func WriteSymlink(destination, link string) (err error)

WriteSymlink creates the symbolic link at the destination location

Types

type Bz2

type Bz2 struct {
	CompressionLevel int
}

func NewBz2

func NewBz2() *Bz2

func (*Bz2) CheckFormat

func (*Bz2) CheckFormat(filename string) error

CheckFormat will check the file sent to the function against the magic numbers for Bzip2. If the file is a Bzip2 the function will not return any error.

func (*Bz2) Extract

func (bz *Bz2) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

type Extractor

type Extractor interface {
	Extract(filename, dest string, p *mpb.Progress, start time.Time) error
}

type File

type File struct {
	os.FileInfo
	Header interface{}
	io.ReadCloser
}

type Format

type Format interface {
	CheckFormat(filename string) error
}

Format to validate file extension.

type Gz

type Gz struct {
	CompressionLevel int
}

func NewGz

func NewGz() *Gz

func (*Gz) CheckFormat

func (gz *Gz) CheckFormat(filename string) error

CheckFormat will check the file sent to the function against the magic numbers for GZip. If the file is a GZip the function will not return any error.

func (*Gz) Extract

func (gz *Gz) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

type IllegalPathError

type IllegalPathError struct {
	Abs      string
	Filename string
}

func (*IllegalPathError) Error

func (e *IllegalPathError) Error() string

type MIME

type MIME struct {
	// contains filtered or unexported fields
}

type Rar

type Rar struct {
	MkdirAll bool
	// contains filtered or unexported fields
}

func NewRar

func NewRar() *Rar

func (*Rar) CheckFormat

func (*Rar) CheckFormat(filename string) error

CheckFormat will check the file sent to the function against the magic numbers for Rar. If the file is a Rar the function will not return any error.

func (*Rar) Close

func (rar *Rar) Close() (err error)

Close will close the Rar archive

func (*Rar) Extract

func (rar *Rar) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

func (*Rar) OpenRarFile

func (rar *Rar) OpenRarFile(file string) (err error)

OpenRarFile will open the Rar file for reading

func (*Rar) Read

func (rar *Rar) Read() (f File, err error)

Read will read the next file in the Rar archive

type ReadFakeCloser

type ReadFakeCloser struct {
	io.Reader
}

ReadFakeCloser is an io.Reader that has a no-op close method to satisfy the io.ReadCloser interface.

func (ReadFakeCloser) Close

func (rfc ReadFakeCloser) Close() error

Close implements io.Closer.

type Tar

type Tar struct {
	MkdirAll bool
	// contains filtered or unexported fields
}

func NewTar

func NewTar() *Tar

func (*Tar) CheckFormat

func (*Tar) CheckFormat(filename string) error

CheckFormat will check the file sent to the funcion against the magic numbers for Tar. If the file is a Tar the function will not return any error.

func (*Tar) Close

func (t *Tar) Close()

Close will close the tar archive

func (*Tar) Extract

func (t *Tar) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

func (*Tar) Open

func (t *Tar) Open(in io.Reader) (err error)

Open will open a tar archive for reading.

func (*Tar) Read

func (t *Tar) Read() (f File, err error)

Read will read the next file in the archive

type TarGz

type TarGz struct {
	*Tar
	CompressionLevel int
	SingleThread     bool
}

TarGz compresses a tar archive

func NewTarGz

func NewTarGz() *TarGz

func (*TarGz) CheckFormat

func (tgz *TarGz) CheckFormat(filename string) (err error)

CheckFormat will check the file sent to the function against magic numbers for Gzip & Tar. If the file is a TarGz the function will not return any error. First will check the file contains the relevant magic number for a GZip file, and if so, will check that the file within contains the magic number for a Tar file.

func (*TarGz) Extract

func (tgz *TarGz) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

func (*TarGz) Open

func (tgz *TarGz) Open(in io.Reader) (err error)

Open will set the Reader in the underlying tar archive then open the archive

type Zip

type Zip struct {
	CompressionLevel    int
	MkdirAll            bool
	SeletiveCompression bool
	FileMethod          uint16
	// contains filtered or unexported fields
}

func NewZip

func NewZip() *Zip

func (*Zip) CheckFormat

func (*Zip) CheckFormat(filename string) error

CheckFormat will check the file sent to the funcion against the magic numbers for Zip. If the file is a Zip the function will not return any error.

func (*Zip) Close

func (z *Zip) Close()

Close will close the Zip archive

func (*Zip) Extract

func (z *Zip) Extract(filename, destination string, p *mpb.Progress, start time.Time) (err error)

Extract will extract the file sent to the function

func (*Zip) Open

func (z *Zip) Open(in io.Reader, size int64) (err error)

Open will open the Zip file for reading

func (*Zip) Read

func (z *Zip) Read() (f File, err error)

Read will read the next file in the Zip archive

type ZipCompressionMethod

type ZipCompressionMethod uint16

ZipCompressionMethod Compression type

Compression methods. see https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT. Note LZMA: Disabled - because 7z isn't able to unpack ZIP+LZMA ZIP+LZMA2 archives made this way - and vice versa.

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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