summaryrefslogtreecommitdiff
path: root/src/lib/io/bytebuffer.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/io/bytebuffer.go')
-rw-r--r--src/lib/io/bytebuffer.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/lib/io/bytebuffer.go b/src/lib/io/bytebuffer.go
index 011166e9c..88371c4b7 100644
--- a/src/lib/io/bytebuffer.go
+++ b/src/lib/io/bytebuffer.go
@@ -39,9 +39,17 @@ func (b *ByteBuffer) Len() int {
return len(b.buf) - b.off
}
+// Truncates the buffer so it contains n bytes.
+// It preserves the data in the buffer at positions [0 : n].
+// It is an error to call b.Truncate(n) with n > b.Len().
+func (b *ByteBuffer) Truncate(n int) {
+ b.buf = b.buf[0 : b.off + n];
+}
+
// Reset resets the buffer so it has no content.
+// b.Reset() is the same as b.Truncate(0).
func (b *ByteBuffer) Reset() {
- b.off = len(b.buf)
+ b.buf = b.buf[0 : b.off];
}
// Write appends the contents of p to the buffer. The return