targz

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 11 Imported by: 1

README

targz

GoDoc Build Status License

Archive directory to tar.gz and extract tar.gz to directory

Example

package main

import (
	"os"

	"github.com/gammazero/targz"
)

func main() {
	// Create archive of backup directory.
	err := targz.Create("/tmp/myfiles/backup", "/tmp/backup.tar.gz")
	if err != nil {
		panic(err)
	}

	// Extract archive into /tmp/restore/ to create /tmp/restore/backup.
	os.MkdirAll("/tmp/restore", 0750)
	err = targz.Extract("/tmp/backup.tar.gz", "/tmp/restore")
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(dir, tarPath string, options ...Option) error

Create creates a gzip compressed tar file containing the contents of the specified directory.

If the directory to archive is specified by a path such as "/tmp/myfiles/backups/weekly", then only the "weekly" directory, and none of its parent path, is added to the tar archive. When extracted, a "weekly" directory is created with all of its archived contents.

func CreateWriter added in v0.0.3

func CreateWriter(dir string, w io.Writer, options ...Option) error

Create writes a gzip compressed tar file to an io.Writer. The tar file contains the contents of the specified directory.

func Extract

func Extract(tarPath, targetDir string) error

Extract reads gzipped tar data from file into a directory.

func ExtractReader added in v0.0.2

func ExtractReader(r io.Reader, targetDir string) error

ExtractReader reads gzipped tar data from io.Reader and extracts it into the target directory.

Types

type Option

type Option func(*config)

Option is a function that sets a value in a config.

func WithIgnore

func WithIgnore(names ...string) Option

WithIgnore specifies file names to ignore when creating an archive. Multiple names to ignore can be specified in a single call and in multiple calls to WithIgnore.

Jump to

Keyboard shortcuts

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