I'm trying to clear a bytes.Buffer
, but there's no such function in the document
Maybe I should just renew the buffer? What's the right way to do it?
buffer = bytes.NewBufferString("") buffer.Grow (30000)
There are two ways to reset a buffer that with content ( length not equal zero ). You can use either Reset() or Truncate() methods found in the bytes. NewBuffer() function.
In go language, the buffer belongs to the byte package of the Go language, and we can use these package to manipulate the byte of the string. For example, suppose we have a string. We can read the length of the string with the len function, which will return the numeric length, but what if the strings are too large.
Package bytes
func (*Buffer) Reset
func (b *Buffer) Reset()
Reset resets the buffer so it has no content. b.Reset() is the same as b.Truncate(0).
func (*Buffer) Truncate
func (b *Buffer) Truncate(n int)
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.
buffer.Reset()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With