shad-go/lectures/10-io/pipe/main.go

21 lines
243 B
Go
Raw Permalink Normal View History

2020-04-23 01:40:13 +00:00
package main
import (
"bytes"
"fmt"
"io"
)
func main() {
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())
}