-
1
-
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
-
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
-
63
-
64
-
65
nio
==========
[](https://godoc.org/github.com/djherbis/nio)
[](https://github.com/djherbis/nio/releases/latest)
[](LICENSE.txt)
[](https://travis-ci.org/djherbis/nio)
[](https://coveralls.io/r/djherbis/nio?branch=master)
[](https://goreportcard.com/report/github.com/djherbis/nio)
Usage
-----
The Buffer interface:
```go
type Buffer interface {
Len() int64
Cap() int64
io.ReadWriter
}
```
nio's Copy method concurrently copies from an io.Reader to a supplied nio.Buffer,
then from the nio.Buffer to an io.Writer. This way, blocking writes don't slow the io.Reader.
```go
import (
"github.com/djherbis/buffer"
"github.com/djherbis/nio"
)
buf := buffer.New(32*1024) // 32KB In memory Buffer
nio.Copy(w, r, buf) // Reads and Writes concurrently, buffering using buf.
```
nio's Pipe method is a buffered version of io.Pipe
The writer return once its data has been written to the Buffer.
The reader returns with data off the Buffer.
```go
import (
"gopkg.in/djherbis/buffer.v1"
"gopkg.in/djherbis/nio.v2"
)
buf := buffer.New(32*1024) // 32KB In memory Buffer
r, w := nio.Pipe(buf)
```
Installation
------------
```sh
go get gopkg.in/djherbis/nio.v2
```
For some pre-built buffers grab:
```sh
go get gopkg.in/djherbis/buffer.v1
```
Mentions
------------
[GopherCon 2017: Peter Bourgon - Evolutionary Optimization with Go](https://www.youtube.com/watch?v=ha8gdZ27wMo&start=2077&end=2140)