Skip to content

Package memio implements Read, Write, Seek, Close and other io methods for a byte slice.

License

Notifications You must be signed in to change notification settings

MJKWoolnough/memio

Repository files navigation

memio

-- import "vimagination.zapto.org/memio"

Package memio implements Read, Write, Seek, Close and other io methods for a byte slice.

Usage

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

type Buffer []byte

Buffer grants a byte slice very straightforward IO methods.

func (*Buffer) Close

func (s *Buffer) Close() error

Close satisfies the io.Closer interface.

func (*Buffer) Peek

func (s *Buffer) Peek(n int) ([]byte, error)

Peek reads the next n bytes without advancing the position.

func (*Buffer) Read

func (s *Buffer) Read(p []byte) (int, error)

Read satisfies the io.Reader interface.

func (*Buffer) ReadAt

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 (*Buffer) ReadByte

func (s *Buffer) ReadByte() (byte, error)

ReadByte satisfies the io.ByteReader interface.

func (*Buffer) ReadFrom

func (s *Buffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom satisfies the io.ReaderFrom interface.

func (*Buffer) ReadRune

func (s *Buffer) ReadRune() (rune, int, error)

ReadRune satisfies the io.RuneReader interface.

func (*Buffer) Write

func (s *Buffer) Write(p []byte) (int, error)

Write satisfies the io.Writer interface.

func (*Buffer) WriteAt

func (s *Buffer) WriteAt(p []byte, off int64) (int, error)

WriteAt satisfies the io.WriteAt interface.

func (*Buffer) WriteByte

func (s *Buffer) WriteByte(b byte) error

WriteByte satisfies the io.ByteWriter interface.

func (*Buffer) WriteString

func (s *Buffer) WriteString(str string) (int, error)

WriteString writes a string to the buffer without casting to a byte slice.

func (*Buffer) WriteTo

func (s *Buffer) WriteTo(w io.Writer) (int64, error)

WriteTo satisfies the io.WriterTo interface.

type LimitedBuffer

type LimitedBuffer []byte

LimitedBuffer grants a byte slice very straightforward IO methods, limiting writing to the capacity of the slice.

func (*LimitedBuffer) Close

func (s *LimitedBuffer) Close() error

Close satisfies the io.Closer interface.

func (*LimitedBuffer) Peek

func (s *LimitedBuffer) Peek(n int) ([]byte, error)

Peek reads the next n bytes without advancing the position.

func (*LimitedBuffer) Read

func (s *LimitedBuffer) Read(p []byte) (int, error)

Read satisfies the io.Reader interface.

func (*LimitedBuffer) ReadAt

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 (*LimitedBuffer) ReadByte

func (s *LimitedBuffer) ReadByte() (byte, error)

ReadByte satisfies the io.ByteReader interface.

func (*LimitedBuffer) ReadFrom

func (s *LimitedBuffer) ReadFrom(r io.Reader) (int64, error)

ReadFrom satisfies the io.ReaderFrom interface.

func (*LimitedBuffer) ReadRune

func (s *LimitedBuffer) ReadRune() (rune, int, error)

ReadRune satisfies the io.RuneReader interface.

func (*LimitedBuffer) Write

func (s *LimitedBuffer) Write(p []byte) (int, error)

Write satisfies the io.Writer interface.

func (*LimitedBuffer) WriteAt

func (s *LimitedBuffer) WriteAt(p []byte, off int64) (int, error)

WriteAt satisfies the io.WriterAt interface.

func (*LimitedBuffer) WriteByte

func (s *LimitedBuffer) WriteByte(b byte) error

WriteByte satisfies the io.ByteWriter interface.

func (*LimitedBuffer) WriteString

func (s *LimitedBuffer) WriteString(str string) (int, error)

WriteString writes a string to the buffer without casting to a byte slice.

func (*LimitedBuffer) WriteTo

func (s *LimitedBuffer) WriteTo(w io.Writer) (int64, error)

WriteTo satisfies the io.WriterTo interface.

type ReadMem

type ReadMem struct {
	*bytes.Reader
}

ReadMem holds a byte slice that can be used for many io interfaces.

func Open

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

func (ReadMem) Close() error

Close is a no-op func the lets ReadMem implement interfaces that require a Close method.

func (ReadMem) Peek

func (r ReadMem) Peek(n int) ([]byte, error)

Peek reads the next n bytes without advancing the position.

type ReadWriteMem

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

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 (*ReadWriteMem) Peek

func (b *ReadWriteMem) Peek(n int) ([]byte, error)

Peek reads the next n bytes without advancing the position.

func (*ReadWriteMem) Read

func (b *ReadWriteMem) Read(p []byte) (int, error)

Read is an implementation of the io.Reader interface.

func (*ReadWriteMem) ReadAt

func (b *ReadWriteMem) ReadAt(p []byte, off int64) (int, error)

ReadAt is an implementation of the io.ReaderAt interface.

func (*ReadWriteMem) ReadByte

func (b *ReadWriteMem) ReadByte() (byte, error)

ReadByte is an implementation of the io.ByteReader interface.

func (*ReadWriteMem) UnreadByte

func (b *ReadWriteMem) UnreadByte() error

UnreadByte implements the io.ByteScanner interface.

func (*ReadWriteMem) WriteTo

func (b *ReadWriteMem) WriteTo(f io.Writer) (int64, error)

WriteTo is an implementation of the io.WriterTo interface.

type String

type String string

String grants a string Read-Only methods.

func (*String) Close

func (s *String) Close() error

Close satisfies the io.Closer interface.

func (*String) Peek

func (s *String) Peek(n int) ([]byte, error)

Peek reads the next n bytes without advancing the position.

func (*String) Read

func (s *String) Read(p []byte) (int, error)

Read satisfies the io.Reader interface.

func (*String) ReadByte

func (s *String) ReadByte() (byte, error)

ReadByte satisfies the io.ByteReader interface.

func (*String) ReadRune

func (s *String) ReadRune() (rune, int, error)

ReadRune satisfies the io.RuneReader interface.

func (*String) WriteTo

func (s *String) WriteTo(w io.Writer) (int64, error)

WriteTo satisfies the io.WriterTo interface.

type WriteMem

type WriteMem struct {
}

WriteMem holds a pointer to a byte slice and allows numerous io interfaces to be used with it.

func Create

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 (*WriteMem) Close

func (b *WriteMem) Close() error

Close is an implementation of the io.Closer interface.

func (*WriteMem) ReadFrom

func (b *WriteMem) ReadFrom(f io.Reader) (int64, error)

ReadFrom is an implementation of the io.ReaderFrom interface.

func (*WriteMem) Seek

func (b *WriteMem) Seek(offset int64, whence int) (int64, error)

Seek is an implementation of the io.Seeker interface.

func (*WriteMem) Truncate

func (b *WriteMem) Truncate(s int64) error

Truncate changes the length of the byte slice to the given amount.

func (*WriteMem) Write

func (b *WriteMem) Write(p []byte) (int, error)

Write is an implementation of the io.Writer interface.

func (*WriteMem) WriteAt

func (b *WriteMem) WriteAt(p []byte, off int64) (int, error)

WriteAt is an implementation of the io.WriterAt interface.

func (*WriteMem) WriteByte

func (b *WriteMem) WriteByte(c byte) error

WriteByte is an implementation of the io.WriteByte interface.

func (*WriteMem) WriteString

func (b *WriteMem) WriteString(s string) (int, error)

WriteString writes a string to the underlying memory.

About

Package memio implements Read, Write, Seek, Close and other io methods for a byte slice.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages