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
+10.1k Use systeminfo to find out installed Windows Hotfix(s) or updates
+61.4k Golang : Convert HTTP Response body to string
+4.3k JavaScript/JQuery : Redirect page examples
+3.8k JavaScript : Rounding number to decimal formats to display currency
+9.2k Golang : cannot assign type int to value (type uint8) in range error
+18.2k Golang : Convert seconds to human readable time format example
+13.1k Golang : How to determine if user agent is a mobile device example
+20.8k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+4.7k Linux/Unix/PHP : Restart PHP-FPM
+8.7k Golang : Identifying Golang HTTP client request
+5.2k Golang : How to solve "too many .rsrc sections" error?
+12.3k Golang : Verify token from Google Authenticator App