pbufio

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 10, 2019 License: MIT Imports: 3 Imported by: 34

Documentation

Overview

Package pbufio contains tools for pooling bufio.Reader and bufio.Writers.

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultWriterPool = NewWriterPool(256, 65536)
	DefaultReaderPool = NewReaderPool(256, 65536)
)

Functions

func GetReader

func GetReader(w io.Reader, size int) *bufio.Reader

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

func GetWriter(w io.Writer, size int) *bufio.Writer

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().

func PutReader

func PutReader(bw *bufio.Reader)

PutReader takes bufio.Reader and its size for future reuse. It does not reuse bufio.Reader if size is not power of two or is out of pool min/max range. PutReader is a wrapper around DefaultReaderPool.Put().

func PutWriter

func PutWriter(bw *bufio.Writer)

PutWriter takes bufio.Writer for future reuse. It does not reuse bufio.Writer which underlying buffer size is not power of PutWriter is a wrapper around DefaultWriterPool.Put().

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) Get

func (rp *ReaderPool) Get(r io.Reader, size int) *bufio.Reader

Get returns bufio.Reader whose buffer has at least size bytes.

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) Get

func (wp *WriterPool) Get(w io.Writer, size int) *bufio.Writer

Get returns bufio.Writer whose buffer has at least size bytes.

func (*WriterPool) Put

func (wp *WriterPool) Put(bw *bufio.Writer)

Put takes ownership of bufio.Writer for further reuse.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL