Skip to content

Commit d3a4e8e

Browse files
dsnetbradfitz
authored andcommitted
compress/gzip: specify when Reader.Header is valid
The gzip package is asymmetrical in the way it handles headers. In Writer, the Header is written on the first call to Write, Flush, or Close. In Reader, the Header is read on calls to NewReader or Reset as opposed to after the first Read. Thus, we document this difference. Fixes #13211 Change-Id: I5f87beff036e5e2fd68a02a15fdb7137e9ca4c37 Reviewed-on: https://go-review.googlesource.com/16838 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 2a031e6 commit d3a4e8e

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/compress/gzip/gunzip.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type Header struct {
6969
// returned by Read as tentative until they receive the io.EOF
7070
// marking the end of the data.
7171
type Reader struct {
72-
Header
72+
Header // valid after NewReader or Reader.Reset
7373
r flate.Reader
7474
decompressor io.ReadCloser
7575
digest hash.Hash32
@@ -83,7 +83,10 @@ type Reader struct {
8383
// NewReader creates a new Reader reading the given reader.
8484
// If r does not also implement io.ByteReader,
8585
// the decompressor may read more data than necessary from r.
86+
//
8687
// It is the caller's responsibility to call Close on the Reader when done.
88+
//
89+
// The Reader.Header fields will be valid in the Reader returned.
8790
func NewReader(r io.Reader) (*Reader, error) {
8891
z := new(Reader)
8992
z.r = makeReader(r)

src/compress/gzip/gzip.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
// A Writer is an io.WriteCloser.
2626
// Writes to a Writer are compressed and written to w.
2727
type Writer struct {
28-
Header
28+
Header // written at first call to Write, Flush, or Close
2929
w io.Writer
3030
level int
3131
wroteHeader bool

0 commit comments

Comments
 (0)