Bytes returns a copy of the raw buffer contents. If no truncation has occurred the full output is returned; otherwise the head and tail portions are concatenated.
()
| 162 | // truncation has occurred the full output is returned; |
| 163 | // otherwise the head and tail portions are concatenated. |
| 164 | func (b *HeadTailBuffer) Bytes() []byte { |
| 165 | b.mu.Lock() |
| 166 | defer b.mu.Unlock() |
| 167 | |
| 168 | tail := b.tailBytes() |
| 169 | if len(tail) == 0 { |
| 170 | out := make([]byte, len(b.head)) |
| 171 | copy(out, b.head) |
| 172 | return out |
| 173 | } |
| 174 | out := make([]byte, len(b.head)+len(tail)) |
| 175 | copy(out, b.head) |
| 176 | copy(out[len(b.head):], tail) |
| 177 | return out |
| 178 | } |
| 179 | |
| 180 | // Len returns the number of bytes currently stored in the |
| 181 | // buffer. |