Standard library / compress/gzip
compress/gzip.ErrHeader
Sentinel indicating an invalid GZIP header. A truncated header can instead return an EOF-related error. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
var ErrHeader 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() { _, e := gzip.NewReader(bytes.NewReader([]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0})) fmt.Println(errors.Is(e, gzip.ErrHeader))}