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
+9.8k Golang : Qt get screen resolution and display on center example
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+7.5k Golang : Dealing with struct's private part
+9.3k Golang : How to get username from email address
+17.4k Golang : Multi threading or run two processes or more example
+17.4k Golang : Get future or past hours, minutes or seconds
+18.4k Golang : Logging with logrus
+17.8k Golang : Defer function inside init()
+20.2k Golang : Reset or rewind io.Reader or io.Writer
+6.5k Grep : How to grep for strings inside binary data
+8.7k Golang : Combine slices but preserve order example