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
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+7.9k Golang Hello World Example
+8.8k Golang : On lambda, anonymous, inline functions and function literals
+13.8k Generate salted password with OpenSSL example
+9.6k Javascript : Read/parse JSON data from HTTP response
+28.2k Golang : Connect to database (MySQL/MariaDB) server
+4.9k Nginx and PageSpeed build from source CentOS example
+4.7k MariaDB/MySQL : Form select statement or search query with Chinese characters
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+7.3k Golang : File system scanning
+22.5k Golang : Convert Unix timestamp to UTC timestamp
+19.8k Golang : Append content to a file