archive

package
v0.20.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2021 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Overview

Package archive defines a set of functions for reading and writing directories and files in a number of tar formats.

Index

Constants

This section is empty.

Variables

View Source
var ErrEntryNotExist = errors.New("not exist")

ErrEntryNotExist is an error returned if an entry path doesn't exist

View Source
var NormalizedDateTime time.Time

Functions

func CreateSingleFileTar

func CreateSingleFileTar(tarFile, path, txt string) error

func CreateSingleFileTarReader

func CreateSingleFileTarReader(path, txt string) io.ReadCloser

func GenerateTar

func GenerateTar(genFn func(TarWriter) error) io.ReadCloser

func GenerateTarWithWriter

func GenerateTarWithWriter(genFn func(TarWriter) error, twf TarWriterFactory) io.ReadCloser

GenerateTarWithTar returns a reader to a tar from a generator function using a writer from the provided factory. Note that the generator will not fully execute until the reader is fully read from. Any errors returned by the generator will be returned when reading the reader.

func IsEntryNotExist

func IsEntryNotExist(err error) bool

IsEntryNotExist detects whether a given error is of type ErrEntryNotExist

func IsZip

func IsZip(file io.Reader) (bool, error)

IsZip detects whether or not a File is a zip directory

func NormalizeHeader

func NormalizeHeader(header *tar.Header, normalizeModTime bool)

NormalizeHeader normalizes a tar.Header

Normalizes the following:

  • ModTime
  • GID
  • UID
  • User Name
  • Group Name

func ReadDirAsTar

func ReadDirAsTar(srcDir, basePath string, uid, gid int, mode int64, normalizeModTime, includeRoot bool, fileFilter func(string) bool) io.ReadCloser

func ReadTarEntry

func ReadTarEntry(rc io.Reader, entryPath string) (*tar.Header, []byte, error)

ReadTarEntry reads and returns a tar file

func ReadZipAsTar

func ReadZipAsTar(srcPath, basePath string, uid, gid int, mode int64, normalizeModTime bool, fileFilter func(string) bool) io.ReadCloser

func WriteDirToTar

func WriteDirToTar(tw TarWriter, srcDir, basePath string, uid, gid int, mode int64, normalizeModTime, includeRoot bool, fileFilter func(string) bool) error

WriteDirToTar writes the contents of a directory to a tar writer. `basePath` is the "location" in the tar the contents will be placed. The includeRoot param sets the permissions and metadata on the root file.

func WriteZipToTar

func WriteZipToTar(tw TarWriter, srcZip, basePath string, uid, gid int, mode int64, normalizeModTime bool, fileFilter func(string) bool) error

WriteZipToTar writes the contents of a zip file to a tar writer.

Types

type TarBuilder

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

func (*TarBuilder) AddDir

func (t *TarBuilder) AddDir(path string, mode int64, modTime time.Time)

func (*TarBuilder) AddFile

func (t *TarBuilder) AddFile(path string, mode int64, modTime time.Time, contents []byte)

func (*TarBuilder) Reader

func (t *TarBuilder) Reader(twf TarWriterFactory) io.ReadCloser

func (*TarBuilder) WriteTo

func (t *TarBuilder) WriteTo(w io.Writer, twf TarWriterFactory) (int64, error)

func (*TarBuilder) WriteToPath

func (t *TarBuilder) WriteToPath(path string, twf TarWriterFactory) error

type TarWriter

type TarWriter interface {
	WriteHeader(hdr *tar.Header) error
	Write(b []byte) (int, error)
	Close() error
}

type TarWriterFactory

type TarWriterFactory interface {
	NewWriter(io.Writer) TarWriter
}

func DefaultTarWriterFactory

func DefaultTarWriterFactory() TarWriterFactory

Jump to

Keyboard shortcuts

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