archiver

package module
v0.0.0-...-46ca01d Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2016 License: MIT Imports: 9 Imported by: 0

README

archiver archiver GoDoc

Package archiver makes it trivially easy to make and extract .zip and .tar.gz files. Simply give the input and output file(s).

Files are put into the root of the archive; directories are recursively added.

Install

go get github.com/mholt/archiver

Library Use

Create a .zip file:

err := archiver.Zip("output.zip", []string{"file.txt", "folder"})

Extract a .zip file:

err := archiver.Unzip("input.zip", "output_folder")

Create a .tar.gz file:

err := archiver.TarGz("output.tar.gz", []string{"file.txt",	"folder"})

Extract a .tar.gz file:

err := archiver.UntarGz("input.tar.gz", "output_folder")

Command Use

Make a new archive:

$ archiver make [archive name] [input files...]

(At least one input file is required.)

To extract an archive:

$ archiver open [archive name] [destination]

(The destination path is optional; default is current directory.)

The archive name must end with a supported file extension like .zip or .tar.gz—this is how it knows what kind of archive to make.

FAQ

Can I list a file to go in a different folder in the archive?

No, because I didn't need it to do that. Just structure your source files to mirror the structure in the archive, like you would normally do when you make an archive using your OS.

Can it add files to an existing archive?

Nope. It just makes new archives or extracts existing ones.

Documentation

Overview

Package archiver makes it super easy to create .zip and .tar.gz archives.

Index

Constants

This section is empty.

Variables

View Source
var CompressedFormats = map[string]struct{}{
	".7z":   {},
	".avi":  {},
	".bz2":  {},
	".gif":  {},
	".gz":   {},
	".jpeg": {},
	".jpg":  {},
	".lz":   {},
	".lzma": {},
	".mov":  {},
	".mp3":  {},
	".mp4":  {},
	".mpeg": {},
	".mpg":  {},
	".png":  {},
	".rar":  {},
	".xz":   {},
	".zip":  {},
	".zipx": {},
}

CompressedFormats is a set of lowercased file extensions for file formats that are typically already compressed. Compressing already-compressed files often results in a larger file. This list is not an exhaustive.

Functions

func TarGz

func TarGz(targzPath string, filePaths []string) error

TarGz creates a .tar.gz file at targzPath containing the contents of files listed in filePaths. File paths can be those of regular files or directories. Regular files are stored at the 'root' of the archive, and directories are recursively added.

func UntarGz

func UntarGz(source, destination string) error

UntarGz untars source and decompresses the contents into destination.

func Unzip

func Unzip(source, destination string) error

Unzip unzips the .zip file at source into destination.

func Zip

func Zip(zipPath string, filePaths []string) error

Zip creates a .zip file in the location zipPath containing the contents of files listed in filePaths. File paths can be those of regular files or directories. Regular files are stored at the 'root' of the archive, and directories are recursively added.

Files with an extension for formats that are already compressed will be stored only, not compressed.

Types

type CompressFunc

type CompressFunc func(string, []string) error

CompressFunc is a function that makes an archive.

type DecompressFunc

type DecompressFunc func(string, string) error

DecompressFunc is a function that extracts an archive.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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