File
Blob: util/buffer_pool.go
| 1 | package util |
| 2 | |
| 3 | import ( |
| 4 | "net/http/httputil" |
| 5 | |
| 6 | pool "github.com/libp2p/go-buffer-pool" |
| 7 | ) |
| 8 | |
| 9 | type BufferPool struct { |
| 10 | bufferSize int |
| 11 | } |
| 12 | |
| 13 | var _ httputil.BufferPool = (*BufferPool)(nil) |
| 14 | |
| 15 | func NewBufferPool(size int) *BufferPool { |
| 16 | return &BufferPool{ |
| 17 | bufferSize: size, |
| 18 | } |
| 19 | } |
| 20 | |
| 21 | func (b *BufferPool) Get() []byte { |
| 22 | return pool.Get(b.bufferSize) |
| 23 | } |
| 24 | |
| 25 | func (b *BufferPool) Put(buf []byte) { |
| 26 | pool.Put(buf) |
| 27 | } |