quickzip

package module
v0.0.0-...-5a2e4d7 Latest Latest
Warning

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

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

README

quickzip

This is an opinionated Zip archiver and extractor with a focus on speed. It is a fork of github.com/saracen/fastzip.

godoc

Changes

  • Added support for modified / created epoch time so all files are extracted with the same time.
  • Added support for skipping file ownership extra information.

License

This project is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMinConcurrency = errors.New("concurrency must be at least 1")
)

Functions

func FlateCompressor

func FlateCompressor(level int) func(w io.Writer) (io.WriteCloser, error)

FlateCompressor returns a pooled performant zip.Compressor configured to a specified compression level. Invalid flate levels will panic.

func FlateDecompressor

func FlateDecompressor() func(r io.Reader) io.ReadCloser

FlateDecompressor returns a pooled performant zip.Decompressor.

func StdFlateCompressor

func StdFlateCompressor(level int) func(w io.Writer) (io.WriteCloser, error)

StdFlateCompressor returns a pooled standard library zip.Compressor configured to a specified compression level. Invalid flate levels will panic.

func StdFlateDecompressor

func StdFlateDecompressor() func(r io.Reader) io.ReadCloser

StdFlateDecompressor returns a pooled standard library zip.Decompressor.

func ZstdCompressor

func ZstdCompressor(level int) func(w io.Writer) (io.WriteCloser, error)

func ZstdDecompressor

func ZstdDecompressor() func(r io.Reader) io.ReadCloser

ZstdDecompressor returns a pooled zstd decoder.

Types

type Archiver

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

Archiver is an opinionated Zip archiver.

Only regular files, symlinks and directories are supported. Only files that are children of the specified chroot directory will be archived.

Access permissions, ownership (unix) and modification times are preserved.

func NewArchiver

func NewArchiver(w io.Writer, opts ...ArchiverOption) (*Archiver, error)

NewArchiver returns a new Archiver.

func (*Archiver) Archive

func (a *Archiver) Archive(ctx context.Context, chroot string, files map[string]os.FileInfo) (err error)

Archive archives all files, symlinks and directories.

func (*Archiver) Close

func (a *Archiver) Close() error

Close closes the underlying ZipWriter.

func (*Archiver) RegisterCompressor

func (a *Archiver) RegisterCompressor(method uint16, comp zip.Compressor)

RegisterCompressor registers custom compressors for a specified method ID. The common methods Store and Deflate are built in.

func (*Archiver) Written

func (a *Archiver) Written() (bytes, entries int64)

Written returns how many bytes and entries have been written to the archive. Written can be called whilst archiving is in progress.

type ArchiverOption

type ArchiverOption func(*archiverOptions) error

ArchiverOption is an option used when creating an archiver.

func WithArchiverBufferSize

func WithArchiverBufferSize(n int) ArchiverOption

WithArchiverBufferSize sets the buffer size for each file to be compressed concurrently. If a compressed file's data exceeds the buffer size, a temporary file is written (to the stage directory) to hold the additional data. The default is 2 mebibytes, so if concurrency is 16, 32 mebibytes of memory will be allocated.

func WithArchiverConcurrency

func WithArchiverConcurrency(n int) ArchiverOption

WithArchiverConcurrency will set the maximum number of files to be compressed concurrently. The default is set to GOMAXPROCS.

func WithArchiverMethod

func WithArchiverMethod(method uint16) ArchiverOption

WithArchiverMethod sets the zip method to be used for compressible files.

func WithArchiverOffset

func WithArchiverOffset(n int64) ArchiverOption

WithArchiverOffset sets the offset of the beginning of the zip data. This should be used when zip data is appended to an existing file.

func WithModifiedEpoch

func WithModifiedEpoch(modifiedEpoch time.Time) ArchiverOption

WithModifiedEpoch sets the modified epoch to be used for the archive.

func WithSkipOwnership

func WithSkipOwnership(skipOwnership bool) ArchiverOption

func WithStageDirectory

func WithStageDirectory(dir string) ArchiverOption

WithStageDirectory sets the directory to be used to stage compressed files before they're written to the archive. The default is the directory to be archived.

type Extractor

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

Extractor is an opinionated Zip file extractor.

Files are extracted in parallel. Only regular files, symlinks and directories are supported. Files can only be extracted to the specified chroot directory.

Access permissions, ownership (unix) and modification times are preserved.

func NewExtractor

func NewExtractor(filename string, opts ...ExtractorOption) (*Extractor, error)

NewExtractor opens a zip file and returns a new extractor.

Close() should be called to close the extractor's underlying zip.Reader when done.

func NewExtractorFromReader

func NewExtractorFromReader(r io.ReaderAt, size int64, opts ...ExtractorOption) (*Extractor, error)

NewExtractor returns a new extractor, reading from the reader provided.

The size of the archive should be provided.

Unlike with NewExtractor(), calling Close() on the extractor is unnecessary.

func (*Extractor) Close

func (e *Extractor) Close() error

Close closes the underlying ZipReader.

func (*Extractor) Extract

func (e *Extractor) Extract(ctx context.Context, chroot string) (err error)

Extract extracts files, creates symlinks and directories from the archive.

func (*Extractor) Files

func (e *Extractor) Files() []*zip.File

Files returns the file within the archive.

func (*Extractor) RegisterDecompressor

func (e *Extractor) RegisterDecompressor(method uint16, dcomp zip.Decompressor)

RegisterDecompressor allows custom decompressors for a specified method ID. The common methods Store and Deflate are built in.

func (*Extractor) Written

func (e *Extractor) Written() (bytes, entries int64)

Written returns how many bytes and entries have been written to disk. Written can be called whilst extraction is in progress.

type ExtractorOption

type ExtractorOption func(*extractorOptions) error

ExtractorOption is an option used when creating an extractor.

func WithExtractorChownErrorHandler

func WithExtractorChownErrorHandler(fn func(name string, err error) error) ExtractorOption

WithExtractorChownErrorHandler sets an error handler to be called if errors are encountered when trying to preserve ownership of extracted files. Returning nil will continue extraction, returning any error will cause Extract() to error.

func WithExtractorConcurrency

func WithExtractorConcurrency(n int) ExtractorOption

WithExtractorConcurrency will set the maximum number of files being extracted concurrently. The default is set to GOMAXPROCS.

Directories

Path Synopsis
examples
internal

Jump to

Keyboard shortcuts

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