Standard library / bytes

bytes.Reader.WriteTo()

Writes remaining bytes to w, advancing the cursor by bytes written; returns count and writer error. Expected stdout: '3 <nil> aé 0\n'.

Formal Syntax & Structure

go syntaxgo
func (r *Reader) WriteTo(w io.Writer) (n int64, err error)

Parameters & Attributes

NameTypeDescription
wio.WriterDestination writer receiving the produced bytes.

Return Value

(n int64, err error)

Writes remaining bytes to w, advancing the cursor by bytes written; returns count and writer error.

Working Example

Example Snippetgo
package main
import (  "bytes"  "fmt"  "strings")
func main() {  r := bytes.NewReader([]byte("aé"))  var b strings.Builder  n, e := r.WriteTo(&b)  fmt.Println(n, e, b.String(), r.Len())}
Go Reference