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
+21.3k Golang : Create and resolve(read) symbolic links
+13.8k Golang : unknown escape sequence error
+6.8k Unix/Linux : How to fix CentOS yum duplicate glibc or device-mapper-libs dependency error?
+11.5k Golang : Generate DSA private, public key and PEM files example
+10.7k Golang : Underscore string example
+7.7k Golang : How to execute code at certain day, hour and minute?
+17k Golang : Get number of CPU cores
+11k Golang : Generate random elements without repetition or duplicate
+11.5k Use systeminfo to find out installed Windows Hotfix(s) or updates
+5.4k Golang *File points to a file or directory ?
+4.6k Javascript : Detect when console is activated and do something about it
+4.4k Linux/MacOSX : Search and delete files by extension