Standard library / compress/flate

compress/flate.Reader

Interface combining io.Reader and io.ByteReader. A source satisfying both can avoid extra buffering and unnecessary reads beyond the compressed stream. Expected stdout: 'Go\n'.

Formal Syntax & Structure

go syntaxgo
type Reader interface {  io.Reader  io.ByteReader}

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() {  var src flate.Reader = bytes.NewReader(pack("Go"))  r := flate.NewReader(src)  p, e := io.ReadAll(r)  must(e)  must(r.Close())  fmt.Println(string(p))}
Go Reference