Golang bytes.Buffer.Truncate() function example
package bytes
Truncate discards all but the first n (1st parameter) unread bytes from the buffer. It panics if n is negative or greater than the length of the buffer.
Golang bytes.Buffer.Truncate() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBuffer([]byte("abcdefg"))
buff.Truncate(2) // keep first 2 bytes and discard the rest
fmt.Println(buff.String())
}
Output :
ab
Reference :
Advertisement
Something interesting
Tutorials
+8.6k Golang : How to check variable or object type during runtime?
+9.7k Golang : Read file with ioutil
+5.5k Golang : Stop goroutine without channel
+10.3k Golang : Wait and sync.WaitGroup example
+46.3k Golang : Read tab delimited file with encoding/csv package
+5.4k Golang : Intercept, inject and replay HTTP traffics from web server
+13.2k Golang : Handle or parse date string with Z suffix(RFC3339) example
+15.5k Golang : Get all local users and print out their home directory, description and group id
+10.5k Golang : cannot assign type int to value (type uint8) in range error
+25.5k Golang : Convert long hexadecimal with strconv.ParseUint example
+6.3k Apt-get to install and uninstall Golang
+14.3k Elastic Search : Mapping date format and sort by date