Truncate discards all but the first n unread bytes from the buffer. It panics if n is negative or greater than the length of the buffer.
(n int)
| 108 | // Truncate discards all but the first n unread bytes from the buffer. |
| 109 | // It panics if n is negative or greater than the length of the buffer. |
| 110 | func (b *Buffer) Truncate(n int) { |
| 111 | if n == 0 { |
| 112 | b.off = 0 |
| 113 | b.buf = b.buf[0:0] |
| 114 | } else { |
| 115 | b.buf = b.buf[0 : b.off+n] |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | // Reset resets the buffer so it has no content. |
| 120 | // b.Reset() is the same as b.Truncate(0). |