Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
(p []byte)
| 302 | // buffer has no data to return, err is io.EOF (unless len(p) is zero); |
| 303 | // otherwise it is nil. |
| 304 | func (b *Buffer) Read(p []byte) (n int, err error) { |
| 305 | if b.off >= len(b.buf) { |
| 306 | // Buffer is empty, reset to recover space. |
| 307 | b.Truncate(0) |
| 308 | if len(p) == 0 { |
| 309 | return |
| 310 | } |
| 311 | return 0, io.EOF |
| 312 | } |
| 313 | n = copy(p, b.buf[b.off:]) |
| 314 | b.off += n |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | // Next returns a slice containing the next n bytes from the buffer, |
| 319 | // advancing the buffer as if the bytes had been returned by Read. |