Documentation
¶
Overview ¶
Package archive lists and extracts single files from release archives.
It handles zip files, tarballs (plain or compressed with gzip, bzip2, xz or zstd) and bare compressed files, detecting the format from the data and falling back to the filename extension. Extraction is deliberately limited to one regular file at a time, written to a path chosen by the caller and capped in size, so the installer never trusts paths or sizes stored in an archive.
Index ¶
Constants ¶
const ( ContainerTar = "tar" ContainerZip = "zip" )
Container formats
const ( CompressionGzip = "gzip" CompressionBzip2 = "bzip2" CompressionXz = "xz" CompressionZstd = "zstd" )
Compression formats
Variables ¶
Functions ¶
func Extract ¶
Extract writes the regular file stored at entryPath in the archive to dst. The output is truncated if it exists and created with mode 0600. At most maxSize bytes are written: larger entries fail with ErrTooLarge and the partial output is removed. A maxSize of zero or less disables the cap.
func List ¶
List returns the entries stored in the archive at path along with the detected format. Only regular files, directories and symlinks are listed; hard links, devices and metadata headers are skipped, as are entries with unsafe names. When the same name appears more than once, the first occurrence wins.
Types ¶
type Entry ¶
type Entry struct {
// Path is the slash separated, cleaned path of the entry inside the
// archive. It is always relative and never escapes the archive root.
Path string
// Mode carries the entry type (regular file, directory or symlink)
// and the permission bits recorded in the archive.
Mode fs.FileMode
// Linkname is the target of symbolic link entries, as stored.
Linkname string
// Head holds the leading bytes of regular files for content sniffing.
// It is shorter than headSize when the file is.
Head []byte
}
Entry describes a file stored in an archive.