archiver

package
v0.0.0-...-9298a07 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package archiver provides archiving and extraction for caches and build artifacts.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrArchiverNotFound is returned if an archiver or extractor format
	// requested has not been registered.
	ErrArchiverNotFound = errors.New("archiver not found")
)
View Source
var ErrTooManyRawFiles = errors.New("only one file can be sent as raw")

ErrTooManyRawFiles is returned if more than one file is passed to the RawArchiver.

Functions

func Has

func Has(format string) bool

Has returns whether an archiver has been registered.

func Register

func Register(format string, archiver NewArchiverCallback, extractor NewExtractorCallback)

Register registers a new archiver.

Types

type Archiver

type Archiver interface {
	Archive(ctx context.Context, files map[string]os.FileInfo) error
}

Archiver is an interface for the Archive method.

func NewArchiver

func NewArchiver(format string, w io.Writer, dir string, level CompressionLevel) (Archiver, error)

NewArchiver returns a new Archiver of the specified format.

The archiver will ensure that files to be archived are children of the directory provided.

func NewGzipArchiver

func NewGzipArchiver(w io.Writer, dir string, level CompressionLevel) (Archiver, error)

NewGzipArchiver returns a new GzipArchiver.

func NewRawArchiver

func NewRawArchiver(w io.Writer, dir string, level CompressionLevel) (Archiver, error)

NewRawArchiver returns a new RawArchiver.

func NewZipArchiver

func NewZipArchiver(w io.Writer, dir string, level CompressionLevel) (Archiver, error)

NewZipArchiver returns a new ZipArchiver.

type CompressionLevel

type CompressionLevel int

CompressionLevel type for specifying a compression level.

const (
	Fastest CompressionLevel = -2
	Fast    CompressionLevel = -1
	Default CompressionLevel = 0
	Slow    CompressionLevel = 1
	Slowest CompressionLevel = 2
)

/ Compression levels from fastest (low/zero compression ratio) to slowest (high compression ratio).

type Extractor

type Extractor interface {
	Extract(ctx context.Context) error
}

Extractor is an interface for the Extract method.

func NewExtractor

func NewExtractor(format string, r io.Reader, dir string) (Extractor, error)

NewExtractor returns a new Extractor of the specified format.

The extractor will extract files to the directory provided.

func NewZipExtractor

func NewZipExtractor(r io.Reader, dir string) (Extractor, error)

NewZipExtractor returns a new ZipExtractor.

type GzipArchiver

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

GzipArchiver is a gzip stream archiver.

func (*GzipArchiver) Archive

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

Archive archives all files as new gzip streams.

type NewArchiverCallback

type NewArchiverCallback func(w io.Writer, dir string, level CompressionLevel) (Archiver, error)

NewArchiverCallback is the callback called when registering a new archiver.

type NewExtractorCallback

type NewExtractorCallback func(r io.Reader, dir string) (Extractor, error)

NewExtractorCallback is the callback called when registering a new extractor.

type RawArchiver

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

RawArchiver is a raw archiver. It doesn't support compression nor multiple files.

func (*RawArchiver) Archive

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

Archive opens and copies a single file to the writer passed to NewRawArchiver. If more than one file is passed, ErrTooManyRawFiles is returned.

type ZipArchiver

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

ZipArchiver is a zip archiver.

func (*ZipArchiver) Archive

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

Archive zips files and writes the stream to the writer passed to NewZipArchiver.

type ZipExtractor

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

ZipExtractor is a zip extractor.

func (*ZipExtractor) Extract

func (e *ZipExtractor) Extract(ctx context.Context) error

Extract extracts files from the reader to the directory passed to NewZipExtractor.

Jump to

Keyboard shortcuts

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