Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
(n int)
| 320 | // If there are fewer than n bytes in the buffer, Next returns the entire buffer. |
| 321 | // The slice is only valid until the next call to a read or write method. |
| 322 | func (b *Buffer) Next(n int) []byte { |
| 323 | m := b.Len() |
| 324 | if n > m { |
| 325 | n = m |
| 326 | } |
| 327 | data := b.buf[b.off : b.off+n] |
| 328 | b.off += n |
| 329 | return data |
| 330 | } |
| 331 | |
| 332 | // ReadByte reads and returns the next byte from the buffer. |
| 333 | // If no byte is available, it returns error io.EOF. |