Golang bytes.Buffer.Reset() function example

package bytes

Reset resets the buffer so it has no content. Buffer.Reset() is the same as Buffer.Truncate(0).

Golang bytes.Buffer.Reset() function usage example

 package main

 import (
 "bytes"
 "fmt"
 )

 func main() {

 buff := bytes.NewBuffer([]byte("abcdefg"))

 fmt.Printf("%d \n", buff.Len())

 // remove all content from the buff buffer
 buff.Reset()

 fmt.Printf("%d \n", buff.Len())
 }

Output :

7

0

Reference :

http://golang.org/pkg/bytes/#Buffer.Reset

Advertisement