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)
|
|
|
|
}
|