Standard library / compress/zlib
compress/zlib.Resetter
Interface implemented by ZLIB readers to reuse decompression state with a new source and dictionary. Reset discards buffered data. Expected stdout: 'Go\n'.
Formal Syntax & Structure
go syntaxgo
type Resetter interface { Reset(r io.Reader, dict []byte) error}Working Example
Example Snippetgo
package main
import ( "bytes" "compress/zlib" "fmt" "io")
func must(e error) { if e != nil { panic(e) }}func pack(s string) []byte { var b bytes.Buffer w := zlib.NewWriter(&b) _, e := w.Write([]byte(s)) must(e) must(w.Close()) return b.Bytes()}func unpack(b []byte) string { r, e := zlib.NewReader(bytes.NewReader(b)) must(e) p, e := io.ReadAll(r) must(e) must(r.Close()) return string(p)}func main() { r, e := zlib.NewReader(bytes.NewReader(pack("old"))) must(e) must(r.(zlib.Resetter).Reset(bytes.NewReader(pack("Go")), nil)) p, e := io.ReadAll(r) must(e) must(r.Close()) fmt.Println(string(p))}