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
+25.7k Golang : missing Mercurial command
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+7.5k Golang : Shuffle strings array
+6.9k Golang : How to setup a disk space used monitoring service with Telegram bot
+17.4k Golang : Check if IP address is version 4 or 6
+12.4k Elastic Search : Return all records (higher than default 10)
+9.1k Golang : Get curl -I or head data from URL example
+16.5k Golang : File path independent of Operating System
+9.1k Golang : Intercept and compare HTTP response code example
+5k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+14.9k Golang : How to check for empty array string or string?
+4.8k Facebook : How to place save to Facebook button on your website