26

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)
daisy
  • 22,498
  • 29
  • 129
  • 265

1 Answers1

48

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()
peterSO
  • 158,998
  • 31
  • 281
  • 276