aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/docker/go-plugins-helpers/sdk/pool.go
blob: 316775973a81669cad73f3c0b167a32a66e2e562 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package sdk

import (
	"io"
	"sync"
)

const buffer32K = 32 * 1024

var buffer32KPool = &sync.Pool{New: func() interface{} { return make([]byte, buffer32K) }}

// copyBuf uses a shared buffer pool with io.CopyBuffer
func copyBuf(w io.Writer, r io.Reader) (int64, error) {
	buf := buffer32KPool.Get().([]byte)
	written, err := io.CopyBuffer(w, r, buf)
	buffer32KPool.Put(buf)
	return written, err
}