From: Guilherme Rezende Date: Mon, 24 Jul 2017 16:19:58 +0000 (-0300) Subject: io: add example for Pipe X-Git-Tag: go1.10beta1~1418 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=5e5a1ed88d2df462aaab68690ef64d35a416966a;p=gostls13.git io: add example for Pipe Change-Id: I24374accf48d43edf4bf27ea6ba2245ddca558ad Reviewed-on: https://go-review.googlesource.com/50910 Reviewed-by: Giovanni Bajo Reviewed-by: Joe Tsai Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot --- diff --git a/src/io/example_test.go b/src/io/example_test.go index af47853726..edcd0086f5 100644 --- a/src/io/example_test.go +++ b/src/io/example_test.go @@ -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 +}