OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Package gzip implements reading and writing of gzip format compressed files, | 5 // Package gzip implements reading and writing of gzip format compressed files, |
6 // as specified in RFC 1952. | 6 // as specified in RFC 1952. |
7 package gzip | 7 package gzip |
8 | 8 |
9 import ( | 9 import ( |
10 "bufio" | 10 "bufio" |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 if err != nil { | 200 if err != nil { |
201 return err | 201 return err |
202 } | 202 } |
203 sum := z.digest.Sum32() & 0xFFFF | 203 sum := z.digest.Sum32() & 0xFFFF |
204 if n != sum { | 204 if n != sum { |
205 return ErrHeader | 205 return ErrHeader |
206 } | 206 } |
207 } | 207 } |
208 | 208 |
209 z.digest.Reset() | 209 z.digest.Reset() |
210 » z.decompressor = flate.NewReader(z.r) | 210 » if z.decompressor == nil { |
| 211 » » z.decompressor = flate.NewReader(z.r) |
| 212 » } else { |
| 213 » » z.decompressor.(flate.Resettable).Reset(z.r, nil) |
| 214 » } |
211 return nil | 215 return nil |
212 } | 216 } |
213 | 217 |
214 func (z *Reader) Read(p []byte) (n int, err error) { | 218 func (z *Reader) Read(p []byte) (n int, err error) { |
215 if z.err != nil { | 219 if z.err != nil { |
216 return 0, z.err | 220 return 0, z.err |
217 } | 221 } |
218 if len(p) == 0 { | 222 if len(p) == 0 { |
219 return 0, nil | 223 return 0, nil |
220 } | 224 } |
(...skipping 25 matching lines...) Expand all Loading... |
246 } | 250 } |
247 | 251 |
248 // Yes. Reset and read from it. | 252 // Yes. Reset and read from it. |
249 z.digest.Reset() | 253 z.digest.Reset() |
250 z.size = 0 | 254 z.size = 0 |
251 return z.Read(p) | 255 return z.Read(p) |
252 } | 256 } |
253 | 257 |
254 // Close closes the Reader. It does not close the underlying io.Reader. | 258 // Close closes the Reader. It does not close the underlying io.Reader. |
255 func (z *Reader) Close() error { return z.decompressor.Close() } | 259 func (z *Reader) Close() error { return z.decompressor.Close() } |
OLD | NEW |