Easily create and extract .zip and .tar.gz files with Go

go get


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.


go get

Library Use

Create a .zip file:

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

Extract a .zip file:

err := archiver.Unzip("", "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.


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.