tar

package
v0.0.0-...-8528295 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetTarSize

func GetTarSize(dat []byte) (int, error)

GetTarSize will return the actual size of the tar file for a byte array containing padded tar data.

func GetTargetFileNames

func GetTargetFileNames(dst string, archive io.Reader) ([]string, error)

GetTargetFileNames will return all file names in the archive provided.

func GetTargetFolderNames

func GetTargetFolderNames(dst string, archive io.Reader) ([]string, error)

GetTargetFolderNames will return all affected folders in the archive provided.

func IsSingleFileArchive

func IsSingleFileArchive(archive []byte) bool

IsSingleFileArchive will return true if there is only 1 file stored in the given archive.

func PackFolder

func PackFolder(src string, buf io.Writer) error

PackFolder will write the given folder as a tar to the given Writer.

func UnpackFile

func UnpackFile(dst, fname string, archive io.Reader, dest io.Writer) error

UnpackFile will extract the given file from the given archive to the given dest writer.

Types

type ConcatReader

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

ConcatReader is an io.Reader that first returns data from a wrapped bytes slice and then continues to return data from a wrapped io.Reader

func NewConcatReader

func NewConcatReader(data []byte, reader io.Reader) *ConcatReader

func (*ConcatReader) Read

func (r *ConcatReader) Read(p []byte) (int, error)

func (*ConcatReader) ReadBytes

func (r *ConcatReader) ReadBytes() int

ReadBytes returns the number of read bytes

type Reader

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

Reader is able to read tar archive uncompressed, compressed with gzip, xz, or bzip2

func NewReader

func NewReader(reader io.Reader) (r *Reader, err error)

func (*Reader) Close

func (r *Reader) Close() error

func (*Reader) Next

func (r *Reader) Next() (*tar.Header, error)

Next advances to the next entry in the tar archive. The Header.Size determines how many bytes can be read for the next file. Any remaining data in the current file is automatically discarded. At the end of the archive, Next returns the error io.EOF.

If Next encounters a non-local name (as defined by filepath.IsLocal) and the GODEBUG environment variable contains `tarinsecurepath=0`, Next returns the header with an [ErrInsecurePath] error. A future version of Go may introduce this behavior by default. Programs that want to accept non-local names can ignore the [ErrInsecurePath] error and use the returned header.

func (*Reader) Read

func (r *Reader) Read(p []byte) (int, error)

Read reads from the current file in the tar archive. It returns (0, io.EOF) when it reaches the end of that file, until [Next] is called to advance to the next file.

If the current file is sparse, then the regions marked as a hole are read back as NUL-bytes.

Calling Read on special types like [TypeLink], [TypeSymlink], [TypeChar], [TypeBlock], [TypeDir], and [TypeFifo] returns (0, io.EOF) regardless of what the [Header.Size] claims.

func (*Reader) ReadBytes

func (r *Reader) ReadBytes() int

ReadBytes returns the number of read bytes

Jump to

Keyboard shortcuts

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