Skip to content

Commit

Permalink
io: add example for Pipe
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
guilhermebr authored and dsnet committed Aug 22, 2017
1 parent 4a1be1e commit 5e5a1ed
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/io/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 5e5a1ed

Please sign in to comment.