Read wraps the underlying Reader's "Read" method. It also captures the number of bytes read, and calls the callback.
(p []byte)
| 34 | // Read wraps the underlying Reader's "Read" method. It also captures the number |
| 35 | // of bytes read, and calls the callback. |
| 36 | func (r *BodyWithCallback) Read(p []byte) (int, error) { |
| 37 | n, err := r.ReadSeekCloser.Read(p) |
| 38 | |
| 39 | if n > 0 { |
| 40 | r.readSize += int64(n) |
| 41 | |
| 42 | if (err == nil || err == io.EOF) && r.c != nil { |
| 43 | err = r.c(r.totalSize, r.readSize, n) |
| 44 | } |
| 45 | } |
| 46 | return n, err |
| 47 | } |
| 48 | |
| 49 | // Seek wraps the underlying Seeker's "Seek" method, updating the number of |
| 50 | // bytes that have been consumed by this reader. |