Documentation ¶
Overview ¶
Package pbufio contains tools for pooling bufio.Reader and bufio.Writers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( DefaultWriterPool = NewWriterPool(256, 65536) DefaultReaderPool = NewReaderPool(256, 65536) )
Functions ¶
func GetReader ¶
GetReader returns bufio.Reader whose buffer has at least size bytes. It returns its capacity for further pass to Put(). Note that size could be ceiled to the next power of two. GetReader is a wrapper around DefaultReaderPool.Get().
func GetWriter ¶
GetWriter returns bufio.Writer whose buffer has at least size bytes. Note that size could be ceiled to the next power of two. GetWriter is a wrapper around DefaultWriterPool.Get().
Types ¶
type ReaderPool ¶
type ReaderPool struct {
// contains filtered or unexported fields
}
ReaderPool contains logic of *bufio.Reader reuse with various size.
func CustomReaderPool ¶
func CustomReaderPool(opts ...pool.Option) *ReaderPool
CustomReaderPool creates new ReaderPool with given options.
func NewReaderPool ¶
func NewReaderPool(min, max int) *ReaderPool
NewReaderPool creates new ReaderPool that reuses writers which size is in logarithmic range [min, max].
func (*ReaderPool) Put ¶
func (rp *ReaderPool) Put(br *bufio.Reader)
Put takes ownership of bufio.Reader for further reuse.
type WriterPool ¶
type WriterPool struct {
// contains filtered or unexported fields
}
WriterPool contains logic of *bufio.Writer reuse with various size.
func CustomWriterPool ¶
func CustomWriterPool(opts ...pool.Option) *WriterPool
CustomWriterPool creates new WriterPool with given options.
func NewWriterPool ¶
func NewWriterPool(min, max int) *WriterPool
NewWriterPool creates new WriterPool that reuses writers which size is in logarithmic range [min, max].
func (*WriterPool) Put ¶
func (wp *WriterPool) Put(bw *bufio.Writer)
Put takes ownership of bufio.Writer for further reuse.