mirror of
https://github.com/cheat/cheat.git
synced 2024-11-23 22:41:35 +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). |
||
---|---|---|
.. | ||
bufpipe.go | ||
doc.go | ||
README.md |
bufpipe: Buffered Pipe
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.
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
How does it differ from bytes.Buffer?
Reads block if the internal buffer is empty until the writer is closed.
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