The archive package provides compressed and stored archive file extraction and content listing functions. See the reference documentation for additional usage and examples.
In your Go project, import the releaser library.
go get github.com/Defacto2/archiveUse the functions.
import"github.com/Defacto2/archive"funcmain() {
// Extract all files from an archive.iferr:=archive.Extract("path/to/archive.zip", "path/to/extract"); err!=nil {
fmt.Println(err)
}
// Extract a specific files from an archive.x:= archive.Extractor{
Source: "path/to/archive.zip",
Destination: "path/to/extract",
}
iferr:=x.Extract("file1.txt", "file2.txt"); err!=nil {
fmt.Println(err)
}
// Extract all files to a temporary directory.path, err:=archive.ExtractSource("path/to/archive.zip", "tempsubdir")
iferr!=nil {
fmt.Println(err)
}
fmt.Println("Extracted to:", path)
// List the contents of an archive.files, err:=archive.List("path/to/archive.zip", "archive.zip")
iferr!=nil {
fmt.Println(err)
}
for_, f:=rangefiles {
fmt.Println(f)
}
// Search for a possible readme file within the list of files.name:=archive.Readme("archive.zip", cont.Files)
fmt.Println(name)
// Compress a file into a new archive.if_, err:=rezip.Compress("file1.txt", "path/to/new.zip"); err!=nil {
fmt.Println(err)
}
// Compress a directory into a new archive.if_, err=rezip.CompressDir("path/to/directory", "path/to/new.zip"); err!=nil {
fmt.Println(err)
}
}