bufpool

package
v0.0.0-...-157c9c8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Get

func Get() *bytes.Buffer

Get returns a Buffer from the pool

func MustWriterToString

func MustWriterToString(w io.WriterTo) string

MustWriterToString takes a WriterTo, writes it's contents to a buffer and returns the value as a string. If there is an error, it panics.

func Put

func Put(buf *bytes.Buffer)

Put returns a buffer from the pool

func PutAndCopy

func PutAndCopy(buf *bytes.Buffer) []byte

PutAndCopy returns the buffer to the pool and returns a copy of it's byte slice

func PutStr

func PutStr(buf *bytes.Buffer) string

PutStr returns a buffer from the pool and returns it's value as a string

func WriterToString

func WriterToString(w io.WriterTo) (string, error)

WriterToString takes a WriterTo, writes it's contents to a buffer and returns the value as a string.

Types

type BufferPool

type BufferPool interface {
	Get() *bytes.Buffer
	Put(buf *bytes.Buffer)
}

BufferPool can Get or Put a Buffer to a pool

var Pool BufferPool = &bufferPool{
	pool: &sync.Pool{
		New: func() interface{} {
			return &bytes.Buffer{}
		},
	},
}

Pool is the package instance of BufferPool.

Jump to

Keyboard shortcuts

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