mirror of
https://github.com/golang/go
synced 2024-11-19 18:44:41 -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:
parent
4a1be1e1da
commit
5e5a1ed88d
@ -243,3 +243,19 @@ func ExampleMultiWriter() {
|
|||||||
// some io.Reader stream to be read
|
// some io.Reader stream to be read
|
||||||
// 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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user