Standard library / compress/gzip
compress/gzip.ErrChecksum
Sentinel returned for a GZIP checksum mismatch. Data returned before the error must not be treated as verified. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
var ErrChecksum errorWorking Example
Example Snippetgo
package main
import ( "bytes" "compress/gzip" "errors" "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() { b := pack("Go") b[len(b)-8] ^= 1 r, e := gzip.NewReader(bytes.NewReader(b)) must(e) _, e = io.ReadAll(r) must(r.Close()) fmt.Println(errors.Is(e, gzip.ErrChecksum))}