archive

package module
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2026 License: MIT Imports: 7 Imported by: 0

README

Documentation

Overview

Package archive creates, lists, and extracts tar.gz archives over streams. Create writes a gzip-compressed tar of filesystem paths to an io.Writer; Extract reads one from an io.Reader into a destination directory, guarding against path-traversal ("zip-slip"); List reports an archive's entry names without writing anything. Every failure carries a sentinel recoverable with errors.Is: ErrCreateArchive, ErrExtract, or — for an entry or symlink target that escapes dest — ErrPathTraversal.

Index

Constants

View Source
const (
	// ErrCreateArchive is the leading sentinel wrapped when a tar.gz archive
	// cannot be created.
	ErrCreateArchive errs.Const = "failed to create archive"
	// ErrExtract is the leading sentinel wrapped when a tar.gz archive cannot be
	// read, listed, or extracted.
	ErrExtract errs.Const = "failed to extract"
	// ErrPathTraversal is the sentinel for a malicious archive entry whose path or
	// symlink target escapes the destination directory. It is distinct from
	// ErrExtract so callers can tell a hostile archive from an I/O fault.
	ErrPathTraversal errs.Const = "archive entry escapes destination"
)

Every error the package can emit is declared as a const of the ecosystem's sentinel-error type errs.Const, so each one is matchable with errors.Is rather than by string comparison. Context and causes are attached with errs.Const.With, which keeps both the sentinel and the cause in the chain.

Variables

This section is empty.

Functions

func Create

func Create(w io.Writer, paths SourcePaths) error

Create writes a tar.gz archive of the given paths to w.

func Extract

func Extract(r io.Reader, dest DestDir) ([]string, error)

Extract reads a tar.gz archive from r and extracts it into dest. Returns the list of extracted paths.

func List

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

List reads a tar.gz archive from r and returns entry names.

Types

type DestDir

type DestDir string

DestDir names the directory an archive is extracted into.

type SourcePaths

type SourcePaths []string

SourcePaths names the filesystem paths to archive.

Jump to

Keyboard shortcuts

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