CopyBytes returns a copy of the bytes contained in the buffer. This slice is safe from updates in the underlying buffer, allowing the buffer to be placed back in the free list.
(buf *bytes.Buffer)
| 28 | // This slice is safe from updates in the underlying buffer, |
| 29 | // allowing the buffer to be placed back in the free list. |
| 30 | func CopyBytes(buf *bytes.Buffer) []byte { |
| 31 | b := buf.Bytes() |
| 32 | b2 := make([]byte, len(b)) |
| 33 | copy(b2, b) |
| 34 | return b2 |
| 35 | } |