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.4k CodeIgniter/PHP : Create directory if does not exist example
+6.1k Golang : Debug with Godebug
+8.7k Golang : How to join strings?
+14.6k Golang : Send email with attachment(RFC2822) using Gmail API example
+5.8k Linux : Disable and enable IPv4 forwarding
+11.9k Golang : Determine if time variables have same calendar day
+7.4k Golang : Word limiter example
+8k Golang : What fmt.Println() can do and println() cannot do
+7.4k Golang : How to detect if a sentence ends with a punctuation?
+15k Golang : How do I get the local IP (non-loopback) address ?
+14.2k Golang : syscall.Socket example