Standard library / archive/zip

archive/zip.File

Represents one ZIP entry and embeds FileHeader metadata. Open reads decoded contents; OpenRaw reads stored bytes. Expected stdout: 'a.txt 2\n'.

Formal Syntax & Structure

go syntaxgo
type File struct {  FileHeader
  // 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 f *zip.File = reader().File[0]; fmt.Println(f.Name, f.UncompressedSize64) }
Go Reference