archive

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsupportedFormat = fmt.Errorf("unsupported archive format")
	ErrFileNotFound      = fmt.Errorf("file not found in archive")
	ErrInvalidData       = fmt.Errorf("invalid archive data")
)

Error definitions

Functions

func CompressFiles

func CompressFiles(w io.Writer, format Format, files map[string]FileEntry) error

CompressFiles creates an archive containing the given files map (filename -> FileEntry) and writes it to the destination io.Writer using the specified format.

func ExtractArchive

func ExtractArchive(archiveData []byte, destDir string) error

ExtractArchive intelligently extracts all contents of an archive into the specified destination directory.

func ExtractBinary

func ExtractBinary(archiveData []byte, binaryName string) ([]byte, error)

ExtractBinary intelligently extracts a named binary from various archive formats based on magic bytes. This is maintained for compatibility and ease of use in simple scenarios.

func NewDecompressReader

func NewDecompressReader(r io.Reader, format Format) (io.Reader, error)

NewDecompressReader creates an io.Reader that decompresses the given reader according to the format. If the format is not a compression stream (e.g. Zip or Raw), it returns the original reader unchanged.

Types

type FileEntry

type FileEntry struct {
	Data    []byte
	Mode    os.FileMode
	ModTime time.Time

	// Tar specific metadata
	Uid        int
	Gid        int
	Uname      string
	Gname      string
	PAXRecords map[string]string // Custom key-value extensions

	// Zip specific metadata
	Comment string
}

FileEntry represents a file to be added to an archive.

type Format

type Format string

Format represents an archive or compression format.

const (
	FormatUnknown Format = "unknown"
	FormatRaw     Format = "raw"
	FormatZip     Format = "zip"
	FormatTar     Format = "tar" // plain tar
	FormatGzip    Format = "gzip"
	FormatBzip2   Format = "bzip2"
	FormatXz      Format = "xz"
	FormatZstd    Format = "zstd"
	FormatLz4     Format = "lz4"
)

func DetectFormat

func DetectFormat(data []byte) Format

DetectFormat attempts to detect the compression or archive format of the given data based on its magic bytes. If no known magic byte matches, it returns FormatRaw.

func (Format) Extension

func (f Format) Extension() string

Extension returns the typical file extension for the format.

func (Format) IsCompression

func (f Format) IsCompression() bool

IsCompression returns true if the format is purely a compression stream (not a container like zip or tar).

func (Format) IsContainer

func (f Format) IsContainer() bool

IsContainer returns true if the format is an archive container (like zip or tar).

func (Format) String

func (f Format) String() string

String returns the string representation of the format.

Jump to

Keyboard shortcuts

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