Standard library / archive/zip

archive/zip.Decompressor

Function type creating a decompression reader. Factory must support concurrent calls; close returned readers. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
type Decompressor func(r io.Reader) io.ReadCloser

Working Example

Example Snippetgo
package main
import (  "archive/zip"  "bytes"  "compress/flate"  "fmt"  "io")
func must(e error) {  if e != nil {    panic(e)  }}func decompressor(r io.Reader) io.ReadCloser { return flate.NewReader(r) }func main() {  var d zip.Decompressor = decompressor  var b bytes.Buffer  w, e := flate.NewWriter(&b, flate.BestSpeed)  must(e)  _, e = w.Write([]byte("Go"))  must(e)  must(w.Close())  r := d(&b)  p, e := io.ReadAll(r)  must(e)  must(r.Close())  fmt.Println(string(p))}
Go Reference