Standard library / bytes
bytes.Buffer.ReadFrom()
Reads from r until EOF, appending bytes; returns count and first non-EOF error. EOF is normal completion. Expected stdout: '2 <nil> go\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Buffer) ReadFrom(r io.Reader) (n int64, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.Reader | Reader supplying bytes until EOF or another error. |
Return Value
(n int64, err error)
Reads from r until EOF, appending bytes; returns count and first non-EOF error. EOF is normal completion.
Working Example
Example Snippetgo
package main
import ( "bytes" "fmt" "strings")
func main() { var b bytes.Buffer n, e := b.ReadFrom(strings.NewReader("go")) fmt.Println(n, e, b.String())}