Standard library / archive/zip
archive/zip.Reader
ZIP archive reader exposing File entries and archive Comment. Implements fs.FS with Open. Expected stdout: '1 true\n'.
Formal Syntax & Structure
go syntaxgo
type Reader struct { File []*File Comment string
// Has unexported fields.}Working Example
Example Snippetgo
package main
import ( "archive/zip" "bytes" "fmt")
func must(e error) { if e != nil { panic(e) }}func archive() []byte { var b bytes.Buffer w := zip.NewWriter(&b) f, e := w.CreateHeader(&zip.FileHeader{Name: "a.txt", Method: zip.Store}) must(e) _, e = f.Write([]byte("Go")) must(e) must(w.Close()) return b.Bytes()}func reader() *zip.Reader { b := archive() r, e := zip.NewReader(bytes.NewReader(b), int64(len(b))) must(e) return r}func main() { var r *zip.Reader = reader(); fmt.Println(len(r.File), r.Comment == "") }