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 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")
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")
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.
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.
Nope. It just makes new archives or extracts existing ones.