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
+6.3k Javascript : Generate random key with specific length
+10.2k Golang : Random Rune generator
+7.5k Golang : Get YouTube playlist
+9.1k Golang : Get curl -I or head data from URL example
+9.4k Golang : Create unique title slugs example
+5.3k Golang : Generate Interleaved 2 inch by 5 inch barcode
+27.6k Golang : dial tcp: too many colons in address
+13.8k Generate salted password with OpenSSL example
+10.6k Golang : Allow Cross-Origin Resource Sharing request
+10.6k Golang : Simple File Server
+9.7k Golang : Find correlation coefficient example
+9.3k Golang : How to get garbage collection data?