Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 24-Mar-2022 | - | ||||
README.md | H A D | 24-Mar-2022 | 1.1 KiB | 43 | 30 | |
bufpipe.go | H A D | 24-Mar-2022 | 3.4 KiB | 129 | 78 | |
doc.go | H A D | 24-Mar-2022 | 82 | 3 | 1 |
README.md
1# bufpipe: Buffered Pipe 2 3[![CircleCI](https://img.shields.io/circleci/build/github/acomagu/bufpipe.svg?style=flat-square)](https://circleci.com/gh/acomagu/bufpipe) [![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](https://godoc.org/github.com/acomagu/bufpipe) 4 5The buffered version of io.Pipe. It's safe for concurrent use. 6 7## How does it differ from io.Pipe? 8 9Writes never block because the pipe has variable-sized buffer. 10 11```Go 12r, w := bufpipe.New(nil) 13io.WriteString(w, "abc") // No blocking. 14io.WriteString(w, "def") // No blocking, too. 15w.Close() 16io.Copy(os.Stdout, r) 17// Output: abcdef 18``` 19 20[Playground](https://play.golang.org/p/PdyBAS3pVob) 21 22## How does it differ from bytes.Buffer? 23 24Reads block if the internal buffer is empty until the writer is closed. 25 26```Go 27r, w := bufpipe.New(nil) 28 29done := make(chan struct{}) 30go func() { 31 io.Copy(os.Stdout, r) // The reads block until the writer is closed. 32 done <- struct{}{} 33}() 34 35io.WriteString(w, "abc") 36io.WriteString(w, "def") 37w.Close() 38<-done 39// Output: abcdef 40``` 41 42[Playground](https://play.golang.org/p/UppmyLeRgX6) 43