1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:44:44 -07:00

io: add example for Pipe

Change-Id: I24374accf48d43edf4bf27ea6ba2245ddca558ad
Reviewed-on: https://go-review.googlesource.com/50910
Reviewed-by: Giovanni Bajo <rasky@develer.com>
Reviewed-by: Joe Tsai <thebrokentoaster@gmail.com>
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Guilherme Rezende 2017-07-24 13:19:58 -03:00 committed by Joe Tsai
parent 4a1be1e1da
commit 5e5a1ed88d

View File

@ -243,3 +243,19 @@ func ExampleMultiWriter() {
// some io.Reader stream to be read
// some io.Reader stream to be read
}
func ExamplePipe() {
r, w := io.Pipe()
go func() {
fmt.Fprint(w, "some text to be read\n")
w.Close()
}()
buf := new(bytes.Buffer)
buf.ReadFrom(r)
fmt.Print(buf.String())
// Output:
// some text to be read
}