bytespipe

package
v28.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClosed is returned when Write is called on a closed BytesPipe.
	ErrClosed = errors.New("write to closed BytesPipe")
)

Functions

This section is empty.

Types

type BytesPipe

type BytesPipe struct {
	// contains filtered or unexported fields
}

BytesPipe is io.ReadWriteCloser which works similarly to pipe(queue). All written data may be read at most once. Also, BytesPipe allocates and releases new byte slices to adjust to current needs, so the buffer won't be overgrown after peak loads.

func New

func New() *BytesPipe

New creates new BytesPipe, initialized by specified slice. If buf is nil, then it will be initialized with slice which cap is 64. buf will be adjusted in a way that len(buf) == 0, cap(buf) == cap(buf).

func (*BytesPipe) Close

func (bp *BytesPipe) Close() error

Close causes further reads from a BytesPipe to return immediately.

func (*BytesPipe) CloseWithError

func (bp *BytesPipe) CloseWithError(err error) error

CloseWithError causes further reads from a BytesPipe to return immediately.

func (*BytesPipe) Read

func (bp *BytesPipe) Read(p []byte) (n int, err error)

Read reads bytes from BytesPipe. Data could be read only once.

func (*BytesPipe) Write

func (bp *BytesPipe) Write(p []byte) (int, error)

Write writes p to BytesPipe. It can allocate new []byte slices in a process of writing.

Jump to

Keyboard shortcuts

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