archive

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

README

archive

A simple Go archiving library.

Example usage

package main

import (
	"github.com/pkg6/archive"
	"log"
	"os"
)

func main() {
	file, err := os.Create("file.zip")
	if err != nil {
		// deal with the error
	}
	zip, err := archive.New(file, "zip")
	if err != nil {
		log.Fatal(err)
	}
	defer zip.Close()
	zip.Add(archive.File{
		Destination: "file.txt",
		Source:      "/path/to/file.txt",
	})
}

Support compression format

  • tar.gz
  • tgz
  • tar
  • gz
  • tar.xz
  • txz
  • tar.zst
  • tzst
  • zip

Documentation

Overview

Package archive implements the Gzip interface providing gz archiving and compression.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Archive

type Archive interface {
	Close() error
	Add(f File) error
}

Archive represents a compression archive files from disk can be written to.

func Copy

func Copy(r *os.File, w io.Writer, format string) (Archive, error)

Copy copies the source archive into a new one, which can be appended at. Source needs to be in the specified format.

func New

func New(w io.Writer, format string) (Archive, error)

New archive.

func NewGzip

func NewGzip(target io.Writer) Archive

NewGzip gz archive.

type File

type File struct {
	Source      string   `yaml:"src,omitempty" json:"src,omitempty"`
	Destination string   `yaml:"dst,omitempty" json:"dst,omitempty"`
	StripParent bool     `yaml:"strip_parent,omitempty" json:"strip_parent,omitempty"`
	Info        FileInfo `yaml:"info,omitempty" json:"info,omitempty"`
	Default     bool     `yaml:"-" json:"-"`
}

type FileInfo

type FileInfo struct {
	Owner       string      `yaml:"owner,omitempty" json:"owner,omitempty"`
	Group       string      `yaml:"group,omitempty" json:"group,omitempty"`
	Mode        os.FileMode `yaml:"mode,omitempty" json:"mode,omitempty"`
	MTime       time.Time   `yaml:"mtime,omitempty" json:"mtime,omitempty"`
	ParsedMTime time.Time   `yaml:"-" json:"-"`
}

FileInfo is the file info of a file.

type Gzip

type Gzip struct {
	// contains filtered or unexported fields
}

Gzip as gz.

func (Gzip) Add

func (a Gzip) Add(f File) error

Add file to the archive.

func (Gzip) Close

func (a Gzip) Close() error

Close all closeables.

type Tar

type Tar struct {
	// contains filtered or unexported fields
}

Tar as tar.

func NewTar

func NewTar(target io.Writer) Tar

NewTar tar archive.

func TarCopy

func TarCopy(source io.Reader, target io.Writer) (Tar, error)

TarCopy creates a new tar with the contents of the given tar.

func (Tar) Add

func (a Tar) Add(f File) error

Add file to the archive.

func (Tar) Close

func (a Tar) Close() error

Close all closeables.

type TarGz

type TarGz struct {
	// contains filtered or unexported fields
}

func NewTarGz

func NewTarGz(target io.Writer) TarGz

NewTarGz tar.gz archive.

func TarGzCopy

func TarGzCopy(source io.Reader, target io.Writer) (TarGz, error)

func (TarGz) Add

func (a TarGz) Add(f File) error

Add file to the archive.

func (TarGz) Close

func (a TarGz) Close() error

Close all closeables.

type TarXz

type TarXz struct {
	// contains filtered or unexported fields
}

TarXz as tar.xz.

func NewTarXz

func NewTarXz(target io.Writer) TarXz

NewTarXz tar.xz archive.

func (TarXz) Add

func (a TarXz) Add(f File) error

Add file to the archive.

func (TarXz) Close

func (a TarXz) Close() error

Close all closeables.

type TarZst

type TarZst struct {
	// contains filtered or unexported fields
}

TarZst as tar.zst.

func NewTarZst

func NewTarZst(target io.Writer) TarZst

NewTarZst tar.zst archive.

func (TarZst) Add

func (a TarZst) Add(f File) error

Add file to the archive.

func (TarZst) Close

func (a TarZst) Close() error

Close all closeables.

type Zip

type Zip struct {
	// contains filtered or unexported fields
}

Zip struct.

func NewZip

func NewZip(target io.Writer) Zip

NewZip zip archive.

func ZipCopy

func ZipCopy(source *os.File, target io.Writer) (Zip, error)

func (Zip) Add

func (a Zip) Add(f File) error

Add a file to the zip archive.

func (Zip) Close

func (a Zip) Close() error

Close all closeables.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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