Standard library / compress/zlib

compress/zlib.ErrHeader

Sentinel indicating an invalid ZLIB header. A truncated header can instead return an EOF-related error. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
var ErrHeader 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() {  _, e := zlib.NewReader(bytes.NewReader([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}))  fmt.Println(errors.Is(e, zlib.ErrHeader))}
Go Reference