io Utility Functions
Copy, TeeReader, MultiWriter.
The io Toolbox
The io package ships small, powerful helpers that combine readers and writers: Copy, TeeReader, MultiWriter, and more.
io.Copy
io.Copy(dst, src) streams all bytes from a reader to a writer and returns the count.
package main
import (
"fmt"
"io"
"os"
"strings"
)
func main() {
n, _ := io.Copy(os.Stdout, strings.NewReader("copied\n"))
fmt.Println("bytes:", n)
}All lessons in this course
- The Reader Interface
- The Writer Interface
- io Utility Functions
- Implementing Custom Readers