archiver

package module
Version: v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2016 License: MIT Imports: 12 Imported by: 7

README

archiver archiver GoDoc Linux Build Status Windows Build Status

Package archiver makes it trivially easy to make and extract common archive formats such as .zip, and .tar.gz. Simply name the input and output file(s).

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

The archiver command runs the same cross-platform and has no external dependencies (not even libc); powered by the Go standard library, dsnet/compress, and nwaples/rardecode. Enjoy!

Supported formats/extensions:

  • .zip
  • .tar.gz
  • .tgz
  • .tar.bz2
  • .rar (open)

Install

go get github.com/mholt/archiver/cmd/archiver

Or download binaries from the releases page.

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—this is how it knows what kind of archive to make. Run archiver -h for more help.

Library Use

import "github.com/mholt/archiver"

Create a .zip file:

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

Extract a .zip file:

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

Working with other file formats is exactly the same, but with their own functions.

FAQ

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

No. This works just like your OS would make an archive in the file explorer: organize your input files to mirror the structure you want in the archive.

Can it add files to an existing archive?

Nope. This is a simple tool; it just makes new archives or extracts existing ones.

Documentation

Overview

Package archiver makes it super easy to create and open .zip, .tar.gz, and .tar.bz2 files.

Index

Constants

This section is empty.

Variables

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

CompressedFormats is a (non-exhaustive) set of lowercased file extensions for formats that are typically already compressed. Compressing already-compressed files often results in a larger file, so when possible, we check this set to avoid that.

Functions

func Rar

func Rar(rarPath string, filePaths []string) error

Rar makes a .rar archive, but this is not implemented because RAR is a proprietary format. It is here only for symmetry with the other archive formats in this package.

func TarBz2

func TarBz2(tarbz2Path string, filePaths []string) error

TarBz2 creates a .tar.bz2 file at tarbz2Path 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 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 Unrar

func Unrar(source, destination string) error

Unrar extracts the RAR file at source and puts the contents into destination.

func UntarBz2

func UntarBz2(source, destination string) error

UntarBz2 untars source and decompresses the contents into destination.

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
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL