An easy to use Go Library for creating and extracting compressed files
go get github.com/johnolafenwa/gozip
package main import "github.com/johnolafenwa/gozip/writer" func main(){ zipWriter,_ := writer.New("Output.zip") zipWriter.AddFolder("path-to-folder","") zipWriter.Save() }
package main import "github.com/johnolafenwa/gozip/reader" func main(){ zipReader, _ := reader.New("path-to-zip-file") zipReader.ExtractTo("Destination-Path") zipReader.Close() }
The Writer supports adding both individual files and folders to a single archive, you can also set the name property to customize the path in the archive where the file will be stored.
package main import "github.com/johnolafenwa/gozip/writer" func main(){ zipWriter,_ := writer.New("MyFiles.zip") //add a single file zipWriter.AddFile("path-to-file/file1.txt","file1.txt") //add a single file, infer name from path zipWriter.AddFile("path-to-file/file2.txt","") //add a folder zipWriter.AddFolder("path-to-folder/FolderOne","FolderOne") //add a folder, infer name from path zipWriter.AddFolder("path-to-folder/FolderTwo","") zipWriter.Save() }
The writer supports two modes for writing zip archives; Store and Deflate. If you want the files compressed, use Store.
zipWriter,_ := writer.New("MyFiles.zip") zipWriter.SetMethod(writer.Deflate)