Standard library / bytes
bytes.Buffer.WriteTo()
Writes unread bytes to w, consuming successfully written bytes; returns byte count and error. A short write without error becomes io.ErrShortWrite. Expected stdout: '2 <nil> go 0\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| w | io.Writer | Destination writer receiving the produced bytes. |
Return Value
(n int64, err error)
Writes unread bytes to w, consuming successfully written bytes; returns byte count and error. A short write without error becomes io.ErrShortWrite.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "strings")
func main() { b := bytes.NewBufferString("go") var w strings.Builder n, e := b.WriteTo(&w) fmt.Println(n, e, w.String(), b.Len())}