1 package bpool
2 3 import (
4 "bytes"
5 "sync"
6 )
7 8 var bpool sync.Pool
9 10 // Get returns a buffer from the pool or creates a new one if
11 // the pool is empty.
12 func Get() *bytes.Buffer {
13 b := bpool.Get()
14 if b == nil {
15 return &bytes.Buffer{}
16 }
17 return b.(*bytes.Buffer)
18 }
19 20 // Put returns a buffer into the pool.
21 func Put(b *bytes.Buffer) {
22 b.Reset()
23 bpool.Put(b)
24 }
25