ReadToWriter reads from the buffer into an io.Writer. N.B. This does not consume the bytes read. TrimFront should be called appropriately after this call in order to do so.
(w io.Writer, count int64)
| 534 | // N.B. This does not consume the bytes read. TrimFront should |
| 535 | // be called appropriately after this call in order to do so. |
| 536 | func (b *Buffer) ReadToWriter(w io.Writer, count int64) (int64, error) { |
| 537 | bytesLeft := int(count) |
| 538 | for v := b.data.Front(); v != nil && bytesLeft > 0; v = v.Next() { |
| 539 | view := v.Clone() |
| 540 | if view.Size() > bytesLeft { |
| 541 | view.CapLength(bytesLeft) |
| 542 | } |
| 543 | n, err := io.Copy(w, view) |
| 544 | bytesLeft -= int(n) |
| 545 | view.Release() |
| 546 | if err != nil { |
| 547 | return count - int64(bytesLeft), err |
| 548 | } |
| 549 | } |
| 550 | return count - int64(bytesLeft), nil |
| 551 | } |
| 552 | |
| 553 | // read implements the io.Reader interface. This method is used by BufferReader |
| 554 | // to consume its underlying buffer. To perform io operations on buffers |