Standard library / compress/zlib

compress/zlib.ErrChecksum

Sentinel returned for a ZLIB checksum mismatch. Data returned before the error must not be treated as verified. Close may repeat the stored read error. Expected stdout: 'true true\n'.

Formal Syntax & Structure

go syntaxgo
var ErrChecksum error

Working Example

Example Snippetgo
package main
import (  "bytes"  "compress/zlib"  "errors"  "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() {  b := pack("Go")  b[len(b)-1] ^= 1  r, e := zlib.NewReader(bytes.NewReader(b))  must(e)  _, e = io.ReadAll(r)  ce := r.Close()  fmt.Println(errors.Is(e, zlib.ErrChecksum), errors.Is(ce, zlib.ErrChecksum))}
Go Reference