Golang bytes.Buffer.WriteTo() function example
package bytes
WriteTo writes data to the given io.Writer interface (1st parameter) until the buffer is drained or an error occurs. The return value n is the number of bytes written; it always fits into an int, but it is int64 to match the io.WriterTo interface. Any error encountered during the write is also returned.
Golang bytes.Buffer.WriteTo() function usage example
package main
import (
"bytes"
"fmt"
)
func main() {
sourcebuffer := bytes.NewBuffer([]byte("abc"))
destbuffer := bytes.NewBuffer(nil)
n, err := sourcebuffer.WriteTo(destbuffer)
fmt.Printf("%s %d %v \n", string(destbuffer.Bytes()),n ,err)
}
Output :
abc 3 <nil>
Reference :
Advertisement
Something interesting
Tutorials
+8.8k Golang : Gorilla web tool kit schema example
+20k Golang : How to run your code only once with sync.Once object
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+7.3k Golang : How to iterate a slice without using for loop?
+7.4k Golang : Scanf function weird error in Windows
+4.9k Javascript : How to get width and height of a div?
+8.1k Golang : Append and add item in slice
+12.7k Golang : Send data to /dev/null a.k.a blackhole with ioutil.Discard
+9.7k Golang : Detect number of active displays and the display's resolution
+12.6k Golang : Transform comma separated string to slice example
+7k Golang : Levenshtein distance example
+13.2k Golang : How to calculate the distance between two coordinates using Haversine formula