CopyTo copies the contents of the buffer to the given byte slice. Caller should ensure that o is of appropriate length.
(o []byte)
| 852 | // CopyTo copies the contents of the buffer to the given byte slice. |
| 853 | // Caller should ensure that o is of appropriate length. |
| 854 | func (b *BytesBuffer) CopyTo(o []byte) int { |
| 855 | offset := 0 |
| 856 | for i, d := range b.data { |
| 857 | if i == len(b.data)-1 { |
| 858 | copy(o[offset:], d[:b.off]) |
| 859 | offset += b.off |
| 860 | } else { |
| 861 | copy(o[offset:], d) |
| 862 | offset += len(d) |
| 863 | } |
| 864 | } |
| 865 | return offset |
| 866 | } |
| 867 | |
| 868 | // TruncateBy reduces the size of the bugger by the given amount. |
| 869 | // Always give back <= touched bytes. |