archive

package module
v0.0.0-...-b690050 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: BSD-3-Clause Imports: 10 Imported by: 0

README

Archive

Tests Analysis

A Go package for easy handling of archive formats like zip and tar (both compressed and compressed).

Supported formats

Tar

Tar archives can be created using the tar package.

The following compression formats are supported:

  • bzip2 (only decompression)
  • gzip
  • xz
  • zstd
Zip

Zip archives can be created using the zip package.

The following compression formats are supported:

  • gzip

Security

This library takes care to make sure that file paths are cleaned to try and avoid path traversals. All close methods that returns errors are also handled accordingly when defered.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidFormat           = errors.New("unsupported archive format")
	ErrZipUnarchiveNotPossible = errors.New("zip unarchive must conform to io.Seeker and io.ReaderAt")
)

Functions

func CreateFromPath

func CreateFromPath(source, target string) error

CreateFromPath uses the contents at the source path and creates a new archive at the target path.

func CreateToWriter

func CreateToWriter(source string, target io.Writer, ext Format) error

CreateToWriter creates a new archive based on the given source and extention. The output is written to the writer that is passed.

func ExtractFromPath

func ExtractFromPath(source, target string) error

ExtractFromPath extracts the archive at the source path to the target path.

func ExtractFromReader

func ExtractFromReader(source io.Reader, target string, ext Format) error

ExtractFromReader takes a source reader, a path to save the archive at and a format to select archive and compression type. Note that .zip files requires the reader to conform to both io.Seeker and io.ReaderAt to work.

Types

type Format

type Format = string
const (
	Zip Format = ".zip" // Zip file extension for a regular zip archive.

	Tar Format = ".tar" // Tar file extension for a regular tar archive.

	// Long versions (two extensions) of compressed tar archive formats.
	TarBzip2 Format = ".tar.bz2" // TarBzip2 file extension for bzip2 compressed tar archive.
	TarGzip  Format = ".tar.gz"  // TarGzip file extension for gzip compressed tar archive.
	TarXz    Format = ".tar.xz"  // TarXz file extension for xz compressed tar archive.
	TarZstd  Format = ".tar.zst" // TarZstd file extension for zstd compressed tar archive.

	// Short versions (one extension) of compressed tar archive formats.
	TarBzip2Short Format = ".tbz2" // TarBzip2 file extension for bzip2 compressed tar archive.
	TarGzipShort  Format = ".tgz"  // TarGzip file extension for gzip compressed tar archive.
	TarXzShort    Format = ".txz"  // TarXz file extension for xz compressed tar archive.
	TarZstdShort  Format = ".tzst" // TarZstd file extension for zstd compressed tar archive.
)

Directories

Path Synopsis
tar
xz

Jump to

Keyboard shortcuts

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