Documentation
¶
Overview ¶
Package bytebuffer provides a buffer type that implements io.ReadWriteSeeker. It also provides an interface for creating byte buffers.
Index ¶
- type Buffer
- func (b *Buffer) Read(p []byte) (n int, err error)
- func (b *Buffer) ReadByte() (byte, error)
- func (b *Buffer) Reset(p []byte)
- func (b *Buffer) Seek(offset int64, whence int) (int64, error)
- func (b *Buffer) Size() int64
- func (b *Buffer) Truncate(size int64) error
- func (b *Buffer) UnreadByte() error
- func (b *Buffer) Write(p []byte) (n int, err error)
- func (b *Buffer) WriteTo(w io.Writer) (n int64, err error)
- type BufferCreator
- type CreateFunc
- type Creator
- type ReadWriteSeekCloser
- type TempFileCreator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer implements the io.Reader, io.WriterTo, io.Writer, io.Seeker, and io.ByteScanner interfaces by reading from or writing to a byte slice. The zero value for Buffer operates like a Buffer of an empty slice.
func (*Buffer) ReadByte ¶
ReadByte implements the io.ByteReader interface.
func (*Buffer) Truncate ¶
Truncate changes the size of the buffer. It does not change the I/O offset.
func (*Buffer) UnreadByte ¶
UnreadByte complements *Buffer.ReadByte in implementing the io.ByteScanner interface.
func (*Buffer) Write ¶
Write implements the io.Writer interface. If Write would extend past the underlying byte slice's capacity, then Write allocates a new byte slice large enough to fit the new bytes. Write returns an error if and only if the byte slice length would exceed an int. If the offset is larger than the length of the underlying byte slice, then the intervening bytes are zero-filled.
type BufferCreator ¶
type BufferCreator struct {
// Limit specifies an maximum limit on size of buffers.
// If Limit is zero, then a reasonable default limit is used.
// If Limit is negative, then no limit is applied.
Limit int
}
BufferCreator is a Creator that returns buffers backed by memory.
func (BufferCreator) CreateBuffer ¶
func (c BufferCreator) CreateBuffer(size int64) (ReadWriteSeekCloser, error)
CreateBuffer returns an in-memory buffer of the given size.
type CreateFunc ¶
type CreateFunc func(size int64) (ReadWriteSeekCloser, error)
CreateFunc is a function that implements Creator.
func (CreateFunc) CreateTemp ¶
func (f CreateFunc) CreateTemp(size int64) (ReadWriteSeekCloser, error)
CreateTemp implements Creator by calling f.
type Creator ¶
type Creator interface {
CreateBuffer(size int64) (ReadWriteSeekCloser, error)
}
A type that implements Creator can create temporary byte buffers. The ReadWriteSeekCloser returned from CreateBuffer must be of the given size and start with its offset at 0. If the size passed to CreateBuffer is less than 1, it indicates that the caller does not know how many bytes will be written to it. A returned ReadWriteSeekCloser values might not permit writes past the ends of its returned buffers. If this is the case, passing a size less than 1 to CreateBuffer should return an error.
type ReadWriteSeekCloser ¶
ReadWriteSeekCloser is an interface that groups the Read, Write, Seek, and Close methods.
type TempFileCreator ¶
TempFileCreator implements Creator with os.CreateTemp. The fields of TempFileCreator are given as arguments to os.CreateTemp.
func (TempFileCreator) CreateBuffer ¶
func (tfc TempFileCreator) CreateBuffer(size int64) (ReadWriteSeekCloser, error)
CreateTemp creates a new temporary file of the given size. The returned file will be removed when calling Close.