Standard library / compress/gzip

compress/gzip.Reader.Multistream()

Control concatenated member decoding. With false, stop at the end of one member; use a byte reader to preserve exact input position, and reapply false after Reset. Expected stdout: 'G o\n'.

Formal Syntax & Structure

go syntaxgo
func (z *Reader) Multistream(ok bool)

Parameters & Attributes

NameTypeDescription
okboolTrue enables concatenated GZIP members; false stops after one member.

Working Example

Example Snippetgo
package main
import (  "bytes"  "compress/gzip"  "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() {  src := bytes.NewReader(append(pack("G"), pack("o")...))  r, e := gzip.NewReader(src)  must(e)  r.Multistream(false)  p, e := io.ReadAll(r)  must(e)  must(r.Reset(src))  r.Multistream(false)  q, e := io.ReadAll(r)  must(e)  must(r.Close())  fmt.Println(string(p), string(q))}
Go Reference