Standard library / compress/gzip
compress/gzip.Reader.Close()
Release decompressor resources without closing the underlying reader. Closing early does not validate the checksum. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func (z *Reader) Close() errorReturn Value
error
Nil on success; otherwise the operation error.
Working Example
Example Snippetgo
package main
import ( "bytes" "compress/gzip" "fmt" "io")
func must(e error) { if e != nil { panic(e) }}func pack(s string) []byte { var b bytes.Buffer w := gzip.NewWriter(&b) _, e := w.Write([]byte(s)) must(e) must(w.Close()) return b.Bytes()}func unpack(b []byte) string { r, e := gzip.NewReader(bytes.NewReader(b)) must(e) p, e := io.ReadAll(r) must(e) must(r.Close()) return string(p)}func main() { r, e := gzip.NewReader(bytes.NewReader(pack("Go"))) must(e) _, e = io.ReadAll(r) must(e) fmt.Println(r.Close() == nil)}