archive

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2017 License: MIT Imports: 13 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dirf

func Dirf(dirname string, nameFmt string, formatName FormatName) (string, error)

Dirf archives a given source directory, and creates an archive with a name in the given format, in the given archive artifact format (FormatName). If the dirname given does not exist, or is not a directory, an error will be returned.

The value of `dirname` can be an absolute or relative path to a directory. It is simply passed into stdlib functions that will resolve this for us.

The `namefmt` needs to have a single `%s` and a single `%c` in it, for both the base dirname and the current unix timestamp, e.g. `"backup-%s-%c"`.

Upon success, the archive filename will be returned.

func Dirsf

func Dirsf(dirnames []string, nameFmt string, formatName FormatName) ([]string, error)

Dirsf takes an array of directory paths as strings, a formatting string for the file names, and a FormatName to identify the type of archive to produce; and produces archives for each of the given directories. If any of the directory names don't exist or aren't directories, an error will be returned.

The values in `dirnames` can be absolute, or relative paths for the directories. These are simply passed into stdlib functions that will resolve this for us.

The `namefmt` needs to have a single `%s` and a single `%d` in it, for both the base dirname and the current unix timestamp, e.g. `"backup-%s-%d"`.

Upon success, an array of the archive filenames will be returned.

func RegisterFormat

func RegisterFormat(name FormatName, producer producerFunc)

RegisterFormat registers an archive artifact format for use by functions that accept a FormatName.

Name is a FormatName which is a string. Any format added should have a corresponding FormatName constant available. Producer is a producerFunc that will create an archive artifact of the appropriate type.

Types

type Artifact

type Artifact interface {
	io.Closer

	// AddFile should take the file at the given path with the given os.FileInfo to the artifact.
	AddFile(path string, info os.FileInfo) error
	// Name returns the artifact's name. In most cases it will be the file name.
	Name() string
}

Artifact represents an archive to be interacted with.

type FormatName

type FormatName string

FormatName is a slightly less than magical string that is used to identify an archive artifact format. If you're creating your own format, you'll also need to declare a FormatName.

const TarGz FormatName = "TarGz"

TarGz is a format for creating gzipped tarballs.

Jump to

Keyboard shortcuts

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