archive

package
v1.21.3 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: BSD-3-Clause-Clear Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FormatTarGz  = "tar.gz"
	FormatTarXz  = "tar.xz"
	FormatTarZst = "tar.zst"
	FormatZip    = "zip"
	FormatSHA256 = "sha256"
	FormatMD5    = "md5"
)

The archive formats Tarbor can produce. Use these rather than string literals, so a typo is a compile error instead of a silent mismatch.

Variables

This section is empty.

Functions

func ResolveMIMEType

func ResolveMIMEType(format string) string

ResolveMIMEType returns the MIME type to upload an archive of the given format with. Unknown formats get the generic application/octet-stream.

func Tar

func Tar(path string) (string, error)

Tar creates an uncompressed tar archive of path, which can be a file or a directory, and returns the path of the archive.

A file is stored under its own name. For a directory, its contents are stored at the root of the archive, without the directory's own name, keeping the structure below it.

The archive is created in the temporary directory and should be removed by the caller when done with it.

Types

type Archive

type Archive struct {
	// Path is where the archive file is on disk.
	Path string

	// Format is the archive format, one of or a concactenation the Format constants.
	Format string

	// Name is the archive's name without the format extension. The file is
	// published as FileName().
	Name string
}

Archive describes an archive file that has been built, or in dry-run mode would be built.

func Gzip

func Gzip(path string, name string) (Archive, error)

Gzip compresses the file at path using gzip and returns an Archive for the result, a temporary file the caller should remove when done. Tar must be used before calling this function.

No file name or modification time is written to the gzip header, so the same input always produces byte-identical output.

func Xz

func Xz(path string, name string) (Archive, error)

Xz compresses the file at path using xz and returns an Archive for the result, a temporary file the caller should remove when done. Tar must be used before calling this function.

func Zip

func Zip(path string, name string) (Archive, error)

Zip creates a zip archive of path, which can be a file or a directory, and returns an Archive for the result, a temporary file the caller should remove when done. Tar is not needed first, since zip is an archive format of its own.

A file is stored under its own name. For a directory, its files are stored relative to it, without the directory's own name. Only files are stored, so empty directories are left out. Symlinks to files are followed and stored as regular files; symlinks to directories are not supported.

Entries keep their permission bits (so executables stay executable) but have no timestamps, which together with the sorted order of the directory walk makes the output the same every time for the same files.

func Zstd

func Zstd(path string, name string) (Archive, error)

Zstd compresses the file at path using zstd and returns an Archive for the result, a temporary file the caller should remove when done. Tar must be used before calling this function.

func (Archive) FileName

func (a Archive) FileName() string

FileName returns the name the archive is published under: its name plus the format extension, e.g. "myapp_1.0.0.tar.gz".

Jump to

Keyboard shortcuts

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