unzipper

package
v0.0.0-...-080ad10 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSkip = errors.New("skip")

ErrSkip is a special error that can be returned from EntryProcessor to skip the extraction of an entry.

Functions

func Unzip

func Unzip(name string, dest string, opts ...Option) error

Types

type AbortErr

type AbortErr struct {
	Err error // Underlying error.
}

AbortErr is a special error that can be returned to abort the extraction of an entry. It's prominent use is during the validation of the file to signal critical errors unrelated to the validity of the file.

func (*AbortErr) Error

func (e *AbortErr) Error() string

func (*AbortErr) Is

func (e *AbortErr) Is(err error) bool

func (*AbortErr) Uwrap

func (e *AbortErr) Uwrap() error

type DuplicateResolver

type DuplicateResolver func(e *Unzipper, name string, a *zip.File, b *zip.File) (*zip.File, error)

DuplicateResolver is a function that is called when two files with the same name are found in the archive. The function is called with the name of the file, the first file and the second file. The function may return the file to use or an error.

type EntryProcessor

type EntryProcessor func(e *Unzipper, name string, f *zip.File, dest string) error

EntryProcessor is a function that is called for each file in the archive before it is extracted, the arguments are as follows: name - name of the file in the archive, f - the file in the archive, dest - the destination (where the file is extracted). The function may process file in any desired way or return SkipErr to skip its extraction.

type ExtractorOptions

type ExtractorOptions struct {
	EntryProcessor    EntryProcessor    // Function to process file before extraction.
	DuplicateResolver DuplicateResolver // Function to resolve duplicate files.
	FileValidator     FileValidator     // Function to validate existing or extracted files.
}

type FileValidator

type FileValidator func(e *Unzipper, name string, dst string, f *os.File) error

FileValidator is a function that is called for each extracted entry together with destination and entry itself, it checks whether the extracted file is valid or not. If the file is invalid, it should return an error, otherwise nil is expected. This function is never called for directories.

type Option

type Option func(*ExtractorOptions)

func WithDuplicateResolver

func WithDuplicateResolver(f DuplicateResolver) Option

func WithEntryProcessor

func WithEntryProcessor(f EntryProcessor) Option

func WithErrOnDuplicates

func WithErrOnDuplicates() Option

WithErrOnDuplicates returns an option that sets the DuplicateResolveFunc to a function that returns an error when two files with the same name are found in the archive.

func WithFileValidator

func WithFileValidator(f FileValidator) Option

WithFileValidator returns an option that sets the FileValidator to the given function.

type Unzipper

type Unzipper struct {
	Entries orderedmap.Map[string, *zip.File] // Map of files in the archive.
	// contains filtered or unexported fields
}

func NewExtractor

func NewExtractor(name string, opts ...Option) (*Unzipper, error)

func (*Unzipper) Close

func (e *Unzipper) Close() error

func (*Unzipper) Unzip

func (e *Unzipper) Unzip(dest string) error

Jump to

Keyboard shortcuts

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