0Pricing
Go Academy · Lesson

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

  1. The Reader Interface
  2. The Writer Interface
  3. io Utility Functions
  4. Implementing Custom Readers
← Back to Go Academy