mirror of
https://github.com/cheat/cheat.git
synced 2024-11-16 08:58:28 +01:00
80c91cbdee
Integrate `go-git` into the application, and use it to `git clone` cheatsheets when the installer runs. Previously, the installer required that `git` be installed on the system `PATH`, so this change has to big advantages: 1. It removes that system dependency on `git` 2. It paves the way for implementing the `--update` command Additionally, `cheat` now performs a `--depth=1` clone when installing cheatsheets, which should at least somewhat improve installation times (especially on slow network connections).
42 lines
1.1 KiB
Markdown
42 lines
1.1 KiB
Markdown
# bufpipe: Buffered Pipe
|
|
|
|
[![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)
|
|
|
|
The buffered version of io.Pipe. It's safe for concurrent use.
|
|
|
|
## How does it differ from io.Pipe?
|
|
|
|
Writes never block because the pipe has variable-sized buffer.
|
|
|
|
```Go
|
|
r, w := bufpipe.New(nil)
|
|
io.WriteString(w, "abc") // No blocking.
|
|
io.WriteString(w, "def") // No blocking, too.
|
|
w.Close()
|
|
io.Copy(os.Stdout, r)
|
|
// Output: abcdef
|
|
```
|
|
|
|
[Playground](https://play.golang.org/p/PdyBAS3pVob)
|
|
|
|
## How does it differ from bytes.Buffer?
|
|
|
|
Reads block if the internal buffer is empty until the writer is closed.
|
|
|
|
```Go
|
|
r, w := bufpipe.New(nil)
|
|
|
|
done := make(chan struct{})
|
|
go func() {
|
|
io.Copy(os.Stdout, r) // The reads block until the writer is closed.
|
|
done <- struct{}{}
|
|
}()
|
|
|
|
io.WriteString(w, "abc")
|
|
io.WriteString(w, "def")
|
|
w.Close()
|
|
<-done
|
|
// Output: abcdef
|
|
```
|
|
|
|
[Playground](https://play.golang.org/p/UppmyLeRgX6)
|