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
+10.2k Golang : Find and replace data in all files recursively
+17.5k Golang : Linked list example
+11.6k Golang : Concurrency and goroutine example
+14.1k Javascript : Prompt confirmation before exit
+14.2k Golang : Convert IP version 6 address to integer or decimal number
+9.8k Golang : Get current, epoch time and display by year, month and day
+21.2k Golang : How to force compile or remove object files first before rebuild?
+5.9k Golang : Extract unicode string from another unicode string example
+9.3k Golang : How to get ECDSA curve and parameters data?
+4.9k Javascript : How to get width and height of a div?
+12.2k Golang : Get remaining text such as id or filename after last segment in URL path
+23k Golang : Calculate time different