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
+16.1k Golang : How to check if input from os.Args is integer?
+43.3k Golang : Convert []byte to image
+7.8k Golang : Example of how to detect which type of script a word belongs to
+33.9k Golang : Call a function after some delay(time.Sleep and Tick)
+5.6k Swift : Get substring with rangeOfString() function example
+10k Golang : Get escape characters \u form from unicode characters
+23.2k Golang : Print out struct values in string format
+36.7k Golang : Display float in 2 decimal points and rounding up or down
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+6.3k Golang : How to get capacity of a slice or array?
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+5.4k Javascript : How to loop over and parse JSON data?