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
+15.3k Golang : Get all local users and print out their home directory, description and group id
+16.1k Golang : How to check if input from os.Args is integer?
+6.8k Get Facebook friends working in same company
+14.7k Golang : Reset buffer example
+6.7k Golang : Experimental emojis or emoticons icons programming language
+7.4k Golang : Scanf function weird error in Windows
+14k Golang : Compress and decompress file with compress/flate example
+13.3k Golang : Linear algebra and matrix calculation example
+5.3k Javascript : Shuffle or randomize array example
+7.5k Gogland : Single File versus Go Application Run Configurations
+8.8k Golang : Gorilla web tool kit schema example
+10.1k Golang : Print how to use flag for your application example