-- import "vimagination.zapto.org/memio"
Package memio implements Read, Write, Seek, Close and other io methods for a byte slice.
var ErrClosed = errors.New("operation not permitted when closed")
ErrClosed is an error returned when trying to perform an operation after using Close().
var (
ErrInvalidUnreadByte = errors.New("invalid UnreadByte, no bytes read")
)
Errors.
type Buffer []byte
Buffer grants a byte slice very straightforward IO methods.
func (s *Buffer) Close() error
Close satisfies the io.Closer interface.
func (s *Buffer) Peek(n int) ([]byte, error)
Peek reads the next n bytes without advancing the position.
func (s *Buffer) Read(p []byte) (int, error)
Read satisfies the io.Reader interface.
func (s *Buffer) ReadAt(p []byte, off int64) (int, error)
ReadAt satisfies the io.ReaderAt interface.
Care should be taken when used in conjunction with any other Read* calls as they will alter the start point of the buffer.
func (s *Buffer) ReadByte() (byte, error)
ReadByte satisfies the io.ByteReader interface.
func (s *Buffer) ReadFrom(r io.Reader) (int64, error)
ReadFrom satisfies the io.ReaderFrom interface.
func (s *Buffer) ReadRune() (rune, int, error)
ReadRune satisfies the io.RuneReader interface.
func (s *Buffer) Write(p []byte) (int, error)
Write satisfies the io.Writer interface.
func (s *Buffer) WriteAt(p []byte, off int64) (int, error)
WriteAt satisfies the io.WriteAt interface.
func (s *Buffer) WriteByte(b byte) error
WriteByte satisfies the io.ByteWriter interface.
func (s *Buffer) WriteString(str string) (int, error)
WriteString writes a string to the buffer without casting to a byte slice.
func (s *Buffer) WriteTo(w io.Writer) (int64, error)
WriteTo satisfies the io.WriterTo interface.
type LimitedBuffer []byte
LimitedBuffer grants a byte slice very straightforward IO methods, limiting writing to the capacity of the slice.
func (s *LimitedBuffer) Close() error
Close satisfies the io.Closer interface.
func (s *LimitedBuffer) Peek(n int) ([]byte, error)
Peek reads the next n bytes without advancing the position.
func (s *LimitedBuffer) Read(p []byte) (int, error)
Read satisfies the io.Reader interface.
func (s *LimitedBuffer) ReadAt(p []byte, off int64) (int, error)
ReadAt satisfies the io.ReaderAt interface.
Care should be taken when used in conjunction with any other Read* calls as they will alter the start point of the buffer.
func (s *LimitedBuffer) ReadByte() (byte, error)
ReadByte satisfies the io.ByteReader interface.
func (s *LimitedBuffer) ReadFrom(r io.Reader) (int64, error)
ReadFrom satisfies the io.ReaderFrom interface.
func (s *LimitedBuffer) ReadRune() (rune, int, error)
ReadRune satisfies the io.RuneReader interface.
func (s *LimitedBuffer) Write(p []byte) (int, error)
Write satisfies the io.Writer interface.
func (s *LimitedBuffer) WriteAt(p []byte, off int64) (int, error)
WriteAt satisfies the io.WriterAt interface.
func (s *LimitedBuffer) WriteByte(b byte) error
WriteByte satisfies the io.ByteWriter interface.
func (s *LimitedBuffer) WriteString(str string) (int, error)
WriteString writes a string to the buffer without casting to a byte slice.
func (s *LimitedBuffer) WriteTo(w io.Writer) (int64, error)
WriteTo satisfies the io.WriterTo interface.
type ReadMem struct {
*bytes.Reader
}
ReadMem holds a byte slice that can be used for many io interfaces.
func Open(data []byte) ReadMem
Open uses a byte slice for reading. Implements io.Reader, io.Seeker,. io.Closer, io.ReaderAt, io.ByteReader and io.WriterTo.
func (ReadMem) Close() error
Close is a no-op func the lets ReadMem implement interfaces that require a Close method.
func (r ReadMem) Peek(n int) ([]byte, error)
Peek reads the next n bytes without advancing the position.
type ReadWriteMem struct {
WriteMem
}
ReadWriteMem is a combination of both the ReadMem and WriteMem types, allowing both all reads and writes to the same underlying byte slice.
func OpenMem(data *[]byte) *ReadWriteMem
OpenMem uses a byte slice for reading and writing. Implements io.Reader, io.Writer, io.Seeker, io.ReaderAt, io.ByteReader, io.WriterTo, io.WriterAt, io.ByteWriter and io.ReaderFrom.
func (b *ReadWriteMem) Peek(n int) ([]byte, error)
Peek reads the next n bytes without advancing the position.
func (b *ReadWriteMem) Read(p []byte) (int, error)
Read is an implementation of the io.Reader interface.
func (b *ReadWriteMem) ReadAt(p []byte, off int64) (int, error)
ReadAt is an implementation of the io.ReaderAt interface.
func (b *ReadWriteMem) ReadByte() (byte, error)
ReadByte is an implementation of the io.ByteReader interface.
func (b *ReadWriteMem) UnreadByte() error
UnreadByte implements the io.ByteScanner interface.
func (b *ReadWriteMem) WriteTo(f io.Writer) (int64, error)
WriteTo is an implementation of the io.WriterTo interface.
type String string
String grants a string Read-Only methods.
func (s *String) Close() error
Close satisfies the io.Closer interface.
func (s *String) Peek(n int) ([]byte, error)
Peek reads the next n bytes without advancing the position.
func (s *String) Read(p []byte) (int, error)
Read satisfies the io.Reader interface.
func (s *String) ReadByte() (byte, error)
ReadByte satisfies the io.ByteReader interface.
func (s *String) ReadRune() (rune, int, error)
ReadRune satisfies the io.RuneReader interface.
func (s *String) WriteTo(w io.Writer) (int64, error)
WriteTo satisfies the io.WriterTo interface.
type WriteMem struct {
}
WriteMem holds a pointer to a byte slice and allows numerous io interfaces to be used with it.
func Create(data *[]byte) *WriteMem
Create uses a byte slice for writing. Implements io.Writer, io.Seeker, io.Closer, io.WriterAt, io.ByteWriter and io.ReaderFrom.
func (b *WriteMem) Close() error
Close is an implementation of the io.Closer interface.
func (b *WriteMem) ReadFrom(f io.Reader) (int64, error)
ReadFrom is an implementation of the io.ReaderFrom interface.
func (b *WriteMem) Seek(offset int64, whence int) (int64, error)
Seek is an implementation of the io.Seeker interface.
func (b *WriteMem) Truncate(s int64) error
Truncate changes the length of the byte slice to the given amount.
func (b *WriteMem) Write(p []byte) (int, error)
Write is an implementation of the io.Writer interface.
func (b *WriteMem) WriteAt(p []byte, off int64) (int, error)
WriteAt is an implementation of the io.WriterAt interface.
func (b *WriteMem) WriteByte(c byte) error
WriteByte is an implementation of the io.WriteByte interface.
func (b *WriteMem) WriteString(s string) (int, error)
WriteString writes a string to the underlying memory.