tarutil

package
v2.0.5+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package tarutil implements some tar utility functions.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCouldNotExtract occurs when an extraction fails.
	ErrCouldNotExtract = errors.New("tarutil: could not extract the archive")

	// ErrExtractedFileTooBig occurs when a file to extract is too big.
	ErrExtractedFileTooBig = errors.New("tarutil: could not extract one or more files from the archive: file too big")

	// MaxExtractableFileSize enforces the maximum size of a single file within a
	// tarball that will be extracted. This protects against malicious files that
	// may used in an attempt to perform a Denial of Service attack.
	MaxExtractableFileSize int64 = 200 * 1024 * 1024 // 200 MiB

)

Functions

This section is empty.

Types

type FilesMap

type FilesMap map[string][]byte

FilesMap is a map of files' paths to their contents.

func ExtractFiles

func ExtractFiles(r io.Reader, filenames []string) (FilesMap, error)

ExtractFiles decompresses and extracts only the specified files from an io.Reader representing an archive.

type TarReadCloser

type TarReadCloser struct {
	*tar.Reader
	io.Closer
}

TarReadCloser embeds a *tar.Reader and the related io.Closer It is the caller's responsibility to call Close on TarReadCloser when done.

func NewTarReadCloser

func NewTarReadCloser(r io.Reader) (*TarReadCloser, error)

NewTarReadCloser attempts to detect the compression algorithm for an io.Reader and returns a TarReadCloser wrapping the Reader to transparently decompress the contents.

Gzip/Bzip2/XZ detection is done by using the magic numbers: Gzip: the first two bytes should be 0x1f and 0x8b. Defined in the RFC1952. Bzip2: the first three bytes should be 0x42, 0x5a and 0x68. No RFC. XZ: the first three bytes should be 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00. No RFC.

func (*TarReadCloser) Close

func (r *TarReadCloser) Close() error

Close cleans up the resources used by a TarReadCloser.

type XzReader

type XzReader struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

XzReader implements io.ReadCloser for data compressed via `xz`.

func NewXzReader

func NewXzReader(r io.Reader) (*XzReader, error)

NewXzReader returns an io.ReadCloser by executing a command line `xz` executable to decompress the provided io.Reader.

It is the caller's responsibility to call Close on the XzReader when done.

func (*XzReader) Close

func (r *XzReader) Close() error

Close cleans up the resources used by an XzReader.

Jump to

Keyboard shortcuts

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