WriteTo implements the io.WriteTo interface for io.Copy and friends.
(w io.Writer)
| 418 | |
| 419 | // WriteTo implements the io.WriteTo interface for io.Copy and friends. |
| 420 | func (f *decompressor) WriteTo(w io.Writer) (int64, error) { |
| 421 | total := int64(0) |
| 422 | flushed := false |
| 423 | for { |
| 424 | if len(f.toRead) > 0 { |
| 425 | n, err := w.Write(f.toRead) |
| 426 | total += int64(n) |
| 427 | if err != nil { |
| 428 | f.err = err |
| 429 | return total, err |
| 430 | } |
| 431 | if n != len(f.toRead) { |
| 432 | return total, io.ErrShortWrite |
| 433 | } |
| 434 | f.toRead = f.toRead[:0] |
| 435 | } |
| 436 | if f.err != nil && flushed { |
| 437 | if f.err == io.EOF { |
| 438 | return total, nil |
| 439 | } |
| 440 | return total, f.err |
| 441 | } |
| 442 | if f.err == nil { |
| 443 | f.doStep() |
| 444 | } |
| 445 | if len(f.toRead) == 0 && f.err != nil && !flushed { |
| 446 | f.toRead = f.dict.readFlush() // Flush what's left in case of error |
| 447 | flushed = true |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | func (f *decompressor) Close() error { |
| 453 | if f.err == io.EOF { |