Golang bytes.Buffer.NewBuffer() function example
package bytes
NewBuffer creates and initializes a new Buffer using the given input as its initial contents. It is intended to prepare a Buffer to read existing data. It can also be used to size the internal buffer for writing. To do that, the new Buffer size should be more than zero and better still is to specify a desired capacity/size.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
Golang bytes.NewBuffer() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
newbuf := bytes.NewBuffer([]byte("abcdefg"))
var buff [7]byte
newbuf.Read(buff[:])
fmt.Println(string(buff[:]))
}
Output :
abcdefg
Reference :
Advertisement
Something interesting
Tutorials
+21.8k Golang : Convert string slice to struct and access with reflect example
+8.2k Golang : Find relative luminance or color brightness
+10.3k Golang : How to check if a website is served via HTTPS
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+5.6k PHP : Fix Call to undefined function curl_init() error
+7.3k Golang : Not able to grep log.Println() output
+6k Golang : Experimenting with the Rejang script
+13.7k Golang : Tutorial on loading GOB and PEM files
+11.9k Golang : Convert(cast) bigint to string
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard