• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..29-Jan-2021-

LICENSEH A D29-Jan-20217.5 KiB166128

README.mdH A D29-Jan-20212.2 KiB6755

bsbuffer.goH A D29-Jan-20213.9 KiB15593

README.md

1# bsbuffer
2`import "github.com/SergeyFrolov/bsbuffer"`
3
4* [Overview](#pkg-overview)
5* [Imported Packages](#pkg-imports)
6* [Index](#pkg-index)
7
8## <a name="pkg-overview">Overview</a>
9
10## <a name="pkg-imports">Imported Packages</a>
11
12No packages beyond the Go standard library are imported.
13
14## <a name="pkg-index">Index</a>
15* [type BSBuffer](#BSBuffer)
16  * [func NewBSBuffer() \*BSBuffer](#NewBSBuffer)
17  * [func (b \*BSBuffer) Read(p []byte) (n int, err error)](#BSBuffer.Read)
18  * [func (b \*BSBuffer) Unblock()](#BSBuffer.Unblock)
19  * [func (b \*BSBuffer) Write(p []byte) (n int, err error)](#BSBuffer.Write)
20
21#### <a name="pkg-files">Package files</a>
22[bsbuffer.go](./bsbuffer.go)
23
24## <a name="BSBuffer">type</a> [BSBuffer](./bsbuffer.go#L17-L29)
25``` go
26type BSBuffer struct {
27    sync.Mutex
28    // contains filtered or unexported fields
29}
30```
31BSBuffer:
32B - Blocking - Read() calls are blocking.
33S - Safe - Supports arbitrary amount of readers and writers.
34Could be unblocked and turned into SBuffer.
35
36### <a name="NewBSBuffer">func</a> [NewBSBuffer](./bsbuffer.go#L32)
37``` go
38func NewBSBuffer() *BSBuffer
39```
40Creates new BSBuffer
41
42### <a name="BSBuffer.Read">func</a> (\*BSBuffer) [Read](./bsbuffer.go#L63)
43``` go
44func (b *BSBuffer) Read(p []byte) (n int, err error)
45```
46Reads data from the BSBuffer, blocking until a writer arrives or the BSBuffer is unblocked.
47If the write end is closed with an error, that error is returned as err; otherwise err is EOF.
48Supports multiple concurrent goroutines and p is valid forever.
49
50### <a name="BSBuffer.Unblock">func</a> (\*BSBuffer) [Unblock](./bsbuffer.go#L108)
51``` go
52func (b *BSBuffer) Unblock()
53```
54Turns BSBuffer into SBuffer: Read() is no longer blocking, but still safe.
55Unblock() is safe to call multiple times.
56
57### <a name="BSBuffer.Write">func</a> (\*BSBuffer) [Write](./bsbuffer.go#L85)
58``` go
59func (b *BSBuffer) Write(p []byte) (n int, err error)
60```
61Non-blocking write appends the contents of p to the buffer, growing the buffer as needed.
62The return value n is the length of p; err is always nil.
63If the buffer becomes too large, Write will panic with ErrTooLarge.
64Supports multiple concurrent goroutines and p is safe for reuse right away.
65
66- - -
67Generated by [godoc2ghmd](https://github.com/GandalfUK/godoc2ghmd)