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 :
Advertisement
Something interesting
Tutorials
+5.4k How to check with curl if my website or the asset is gzipped ?
+24.5k Golang : Change file read or write permission example
+9.2k Golang : Create and shuffle deck of cards example
+5.8k Golang : Markov chains to predict probability of next state example
+8.9k Golang : Sort lines of text example
+16.3k Golang : Find out mime type from bytes in buffer
+30.9k error: trying to remove "yum", which is protected
+18.4k Golang : How to remove certain lines from a file
+17.8k Golang : Defer function inside init()
+19.3k Golang : Get host name or domain name from IP address
+13.7k Golang : Activate web camera and broadcast out base64 encoded images
+23.5k Golang : Get ASCII code from a key press(cross-platform) example