tarutil

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 14 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrOutsideDest = errors.New("member leads outside the destination")

Member that would land, or link, outside the extraction directory

View Source
var ErrTooLarge = errors.New("member does not fit in the space left on the destination")

Member whose content would not fit in the space left on the destination's volume, the guard against decompression bombs

View Source
var ErrUnsafePath = errors.New("unsafe member path")

Member name that is empty, absolute, on a drive or share, or climbing out through a dot-dot element

View Source
var ErrUnsupportedType = errors.New("unsupported member type")

Member of a kind extraction does not create: a device, a fifo, or a link where links are refused

Functions

func CreateTarGz

func CreateTarGz(base, rootDir, baseDir string) (string, error)

Writes base.tar.gz in GNU format holding the tree at rootDir/baseDir under the name baseDir, entries in sorted order, symbolic links stored as links and every hard link as a file of its own, through a temp file beside it that is flushed and renamed into place once complete and removed on any failure or panic; gives back the archive path

func Extract

func Extract(r io.Reader, dest string, o ExtractOptions) error

Extracts a tar stream below dest, made when missing: directories, regular files with owner read and write added and no setuid, setgid or write bits for others, owner execute deciding execute for all, and links when allowed; every name must pass MemberParts and resolve inside dest, a link's target too, judged where the system will follow it, a refused member stopping the extraction with a *MemberError; content that would not fit in the space left on dest's volume is refused with ErrTooLarge before it is written; modification times are restored, directories' last

func ExtractTarGz

func ExtractTarGz(archive, dest string) error

Extracts the gzip compressed tar file at archive below dest like Extract with links refused, so only directories and regular files come out

func MemberNames

func MemberNames(r io.Reader) ([]string, error)

Names of the members of a tar stream in stream order, a directory's trailing slash dropped

func MemberParts

func MemberParts(name string) ([]string, error)

Relative path elements of an archive member name split at / and \, empty and . elements dropped; a name that is empty, absolute, on a drive or share, has no element left or holds a .. element fails with a *MemberError wrapping ErrUnsafePath

func RootDirs

func RootDirs(archive string) (map[string]bool, error)

Top level directory names of the gzip compressed tar file at archive, a name counting through a directory member or any member below it; an unsafe member name fails it with a *MemberError

Types

type Adder

type Adder struct {
	W                *tar.Writer
	Format           tar.Format
	FlattenHardLinks bool
	// contains filtered or unexported fields
}

Writer of files and trees into the tar stream W, directories in sorted order and symbolic links stored unfollowed; a file met again through another hard link becomes a link member naming the member it was first written as, unless FlattenHardLinks stores its content again, and a non-zero Format is set on every header

func (*Adder) Add

func (a *Adder) Add(path, name string, recursive bool, filter func(*tar.Header) *tar.Header) error

Adds the file or directory at path as the member name, a directory's entries below it too when recursive; filter may change each header, or drop the member and a dropped directory's entries by giving back nil; sockets, fifos and devices are skipped, carrying no content and being refused by every extraction here

type ExtractOptions

type ExtractOptions struct {
	Links bool
}

Settings of Extract: Links extracts symbolic and hard links that resolve inside the destination, refusing them with ErrUnsupportedType when false

type MemberError

type MemberError struct {
	Name string
	Err  error
}

Archive member refused by its name, kind or size, wrapping ErrUnsafePath, ErrOutsideDest, ErrUnsupportedType or ErrTooLarge

func (*MemberError) Error

func (e *MemberError) Error() string

The member and the reason, as in archive member "../x": unsafe member path

func (*MemberError) Unwrap

func (e *MemberError) Unwrap() error

The reason

Jump to

Keyboard shortcuts

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