-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
main.go
41 lines (29 loc) · 759 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package main
import (
"io"
"os"
)
func main() {
src, err := os.Open("src.txt")
if err != nil {
panic(err)
}
defer src.Close()
dst1, err := os.Create("dst1.txt")
if err != nil {
panic(err)
}
defer dst1.Close()
dst2, err := os.Create("dst2.txt")
if err != nil {
panic(err)
}
defer dst2.Close()
rdr := io.TeeReader(src, dst1)
rdr = io.TeeReader(rdr, os.Stdout)
io.Copy(dst2, rdr)
}
/*
func TeeReader(r Reader, w Writer) Reader
TeeReader returns a Reader that writes to w what it reads from r. All reads from r performed through it are matched with corresponding writes to w. There is no internal buffering - the write must complete before the read completes. Any error encountered while writing is reported as a read error.
*/