shad-go/lectures/10-io/teereader/main.go

28 lines
354 B
Go
Raw Normal View History

2020-04-23 01:40:13 +00:00
package main
import (
"bytes"
"fmt"
"io"
"log"
"strings"
)
func main() {
r := strings.NewReader("some io.Reader stream to be read\n")
var buf bytes.Buffer
tee := io.TeeReader(r, &buf)
printall := func(r io.Reader) {
2022-04-21 15:13:36 +00:00
b, err := io.ReadAll(r)
2020-04-23 01:40:13 +00:00
if err != nil {
log.Fatal(err)
}
fmt.Printf("%s", b)
}
printall(tee)
printall(&buf)
}