Skip to content

Commit

Permalink
Consume z.current prepared by Reader.Read in Reader.WriteTo (#50)
Browse files Browse the repository at this point in the history
... to fix missing data when WriteTo is called after Read.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
  • Loading branch information
mtrmac committed Sep 30, 2022
1 parent f5d9792 commit 17e8dac
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions gunzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,19 @@ func (z *Reader) Read(p []byte) (n int, err error) {

func (z *Reader) WriteTo(w io.Writer) (n int64, err error) {
total := int64(0)
avail := z.current[z.roff:]
if len(avail) != 0 {
n, err := w.Write(avail)
if n != len(avail) {
return total, io.ErrShortWrite
}
total += int64(n)
if err != nil {
return total, err
}
z.blockPool <- z.current
z.current = nil
}
for {
if z.err != nil {
return total, z.err
Expand Down

0 comments on commit 17e8dac

Please sign in to comment.