Standard library / compress/flate
compress/flate.Resetter
Interface for reusing a DEFLATE decompressor with a new source and optional dictionary, discarding previous buffered state. 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/flate" "fmt" "io")
func must(e error) { if e != nil { panic(e) }}func pack(s string) []byte { var b bytes.Buffer w, e := flate.NewWriter(&b, flate.DefaultCompression) must(e) _, e = w.Write([]byte(s)) must(e) must(w.Close()) return b.Bytes()}func unpack(b []byte) string { r := flate.NewReader(bytes.NewReader(b)) p, e := io.ReadAll(r) must(e) must(r.Close()) return string(p)}func main() { r := flate.NewReader(bytes.NewReader(pack("old"))) must(r.(flate.Resetter).Reset(bytes.NewReader(pack("Go")), nil)) p, e := io.ReadAll(r) must(e) must(r.Close()) fmt.Println(string(p))}