Standard library / bufio
bufio.Writer.ReadFrom()
Copies a reader into the writer; some final bytes may remain buffered, so Flush is still necessary. Expected stdout: '3 abc <nil>\n'.
Formal Syntax & Structure
go syntaxgo
func (b *Writer) ReadFrom(r io.Reader) (n int64, err error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| r | io.Reader | Source reader. |
Return Value
(n int64, err error)
Copies a reader into the writer; some final bytes may remain buffered, so Flush is still necessary.
Working Example
Example Snippetgo
package main
import ( "bufio" "bytes" "fmt" "strings")
func main() { var b bytes.Buffer w := bufio.NewWriter(&b) n, e := w.ReadFrom(strings.NewReader("abc")) w.Flush() fmt.Println(n, b.String(), e)}