karchive

package
v0.0.0-...-895b022 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decoder

func Decoder(name string, current io.Reader) (string, io.Reader, error)

func MkdirAll

func MkdirAll(dir string, perm os.FileMode) ([]string, error)

MkdirAll is just like os.MkdirAll, except it returns the set of directories created.

func Untar

func Untar(r io.Reader, dir string, mods ...Modifier) error

Untar opens a .tar file (no compression), and unpacks it in the specified directory.

Untar can only create regular files, symlinks, and directories. The presence of any other kind of file in the archive will cause the opening to fail.

Except for targets of symlinks, if the tar contains files named like '../../../', they won't be allowed to escape the unpack directory: all unpacked files will be placed in a subdirectory of dir, no matter what.

func Untarz

func Untarz(name string, r io.Reader, dest string, mods ...Modifier) error

Untarz opens a .tar.{gz,xz,bz2} file, and unpacks it by invoking Untar.

Types

type Modifier

type Modifier func(*options)

func WithDefaultDirMode

func WithDefaultDirMode(mode os.FileMode) Modifier

WithDefaultDirMode sets the privileges to use to create unknown directories.

Tar files normally contain directory and file definitions, with files in sub directories always appearing after the definition of the directory they appear in.

However, this is not mandated. There can be tar files that define files, but not the directories. Or where the directory definition is after the file definition.

WithDefaultDirMode defines the mode to use to create directories that are necessary to unpack a file, but for which a definition has not been seen in the tar yet.

If a definition is seen later on while unpacking the file, that definition will be used, and the privileges here will only be temporarily used. If a definition is not seen, the privileges here will be the final ones.

func WithDirUmask

func WithDirUmask(umask uint32) Modifier

WithDirUmask sets an umask for written directories.

The default dir umask is 0, meaning that whatever is set in the .tar file will actually be used.

For example: WithDirUmask(0222) will result in no dir being writable.

func WithFileUmask

func WithFileUmask(umask uint32) Modifier

WithFileUmask sets an umask for written files.

The default file umask is 0, meaning that whatever is set in the .tar file will actually be used.

For example: WithFileUmask(0222) will result in no file being writable.

type Modifiers

type Modifiers []Modifier

func (Modifiers) Apply

func (m Modifiers) Apply(o *options)

type TempUnzipDir

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

TempUnzipDir wraps a path to a temp directory that contains the contents of an unzipped archive.

func Unzip

func Unzip(ctx context.Context, zipPath string) (*TempUnzipDir, error)

Unzip unzips the supplied ZIP file to a temp directory, returning a handle to the unzipped archive. This handle should be closed when the file contents are no longer in-use.

func (*TempUnzipDir) Close

func (d *TempUnzipDir) Close() error

Close deletes the underlying temporary directory.

func (*TempUnzipDir) Path

func (d *TempUnzipDir) Path(relPath string) string

Path returns an absolute path to a file on disk for a path relative to the root of the archive.

func (*TempUnzipDir) Root

func (d *TempUnzipDir) Root() string

Root returns the path to the temporary directory, which is the root of the unzipped archive.

Jump to

Keyboard shortcuts

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