Golang bytes.Buffer.Bytes() function example
package bytes
Bytes returns a slice of the contents of the unread portion of the buffer; len(buffer.Bytes()) == buffer.Len(). If the caller changes the contents of the returned slice, the contents of the buffer will change provided there are no intervening method calls on the Buffer.
Golang bytes.Buffer.Bytes() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
buff := bytes.NewBufferString("abcdefghi")
unread := buff.Bytes()
fmt.Println(string(unread)) // since nothing has been read. it will return everything
var readbuff [3]byte
buff.Read(readbuff[0:2])
unread2 := buff.Bytes() // this time only return the unread portion
fmt.Println(string(unread2))
}
Output :
abcdefghi
cdefghi
Reference :
Advertisement
Something interesting
Tutorials
+30.4k Golang : How to verify uploaded file is image or allowed file types
+46.2k Golang : Read tab delimited file with encoding/csv package
+11.1k Golang : How to determine a prime number?
+5.9k Golang : Use NLP to get sentences for each paragraph example
+4.9k HTTP common errors and their meaning explained
+13.1k Golang : Convert(cast) uintptr to string example
+7.7k Golang : Command line ticker to show work in progress
+37.5k Golang : Converting a negative number to positive number
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+9k Golang : automatically figure out array length(size) with three dots
+21.7k Golang : Setting up/configure AWS credentials with official aws-sdk-go
+14k Golang : Reverse IP address for reverse DNS lookup example