Help us shape the future of Go! Take the 2026 Go Developer Survey

wrapio

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 3 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(w DoerAt, p []byte, off int64, wrapAt int64) (n int, err error)

Wrap causes an action on an array of bytes (like read/write) to be done from an offset off, wrapping at offset wrapAt.

Types

type DoAtFunc

type DoAtFunc func([]byte, int64) (int, error)

DoAtFunc is implemented by ReadAt/WriteAt

type DoerAt

type DoerAt interface {
	DoAt([]byte, int64) (int, error)
}

DoerAt is a common interface for wrappers WriteAt or ReadAt functions

type ReadWriterAt

type ReadWriterAt interface {
	io.ReaderAt
	io.WriterAt
}

ReadWriterAt implements io.ReaderAt and io.WriterAt

type WrapReader

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

WrapReader wraps reads around a section of data.

func NewWrapReader

func NewWrapReader(r io.ReaderAt, off int64, wrapAt int64) *WrapReader

NewWrapReader creates a WrapReader starting at offset off, and wrapping at offset wrapAt.

func (WrapReader) DoAt

func (w WrapReader) DoAt(p []byte, off int64) (n int, err error)

func (WrapReader) Offset

func (w WrapReader) Offset() int64

func (*WrapReader) Read

func (r *WrapReader) Read(p []byte) (n int, err error)

Read reads into p starting at the current offset, wrapping if it reaches the end. The current offset is shifted forward by the amount read.

func (*WrapReader) ReadAt

func (r *WrapReader) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads into p starting at the current offset, wrapping when it reaches the end.

func (WrapReader) Seek

func (w WrapReader) Seek(offset int64, whence int) (int64, error)

type WrapWriter

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

WrapWriter wraps writes around a section of data.

func NewWrapWriter

func NewWrapWriter(w io.WriterAt, off int64, wrapAt int64) *WrapWriter

NewWrapWriter creates a WrapWriter starting at offset off, and wrapping at offset wrapAt.

func (WrapWriter) DoAt

func (w WrapWriter) DoAt(p []byte, off int64) (n int, err error)

func (WrapWriter) Offset

func (w WrapWriter) Offset() int64

func (WrapWriter) Seek

func (w WrapWriter) Seek(offset int64, whence int) (int64, error)

func (*WrapWriter) Write

func (w *WrapWriter) Write(p []byte) (n int, err error)

Write writes p starting at the current offset, wrapping when it reaches the end. The current offset is shifted forward by the amount written.

func (*WrapWriter) WriteAt

func (w *WrapWriter) WriteAt(p []byte, off int64) (n int, err error)

WriteAt writes p starting at offset off, wrapping when it reaches the end.

type Wrapper

type Wrapper struct {
	// N is the offset at which to "wrap" back to the start
	N int64
	// L is the length of the data written
	L int64
	// O is our offset in the data
	O int64
	// contains filtered or unexported fields
}

Wrapper implements a io.ReadWriter and ReadWriterAt such that when reading/writing goes past N bytes, it "wraps" back to the beginning.

func NewWrapper

func NewWrapper(rwa ReadWriterAt, L, O, N int64) *Wrapper

NewWrapper creates a Wrapper based on ReadWriterAt rwa. L is the current length, O is the current offset, and N is offset at which we "wrap".

func (*Wrapper) Cap

func (wpr *Wrapper) Cap() int64

Cap returns the "wrap" offset (max # of bytes)

func (*Wrapper) Len

func (wpr *Wrapper) Len() int64

Len returns the # of bytes in the Wrapper

func (*Wrapper) Read

func (wpr *Wrapper) Read(p []byte) (n int, err error)

Read reads from the current offset into p, wrapping at Cap()

func (*Wrapper) ReadAt

func (wpr *Wrapper) ReadAt(p []byte, off int64) (n int, err error)

ReadAt reads from the current offset+off into p, wrapping at Cap()

func (*Wrapper) Reset

func (wpr *Wrapper) Reset()

Reset seeks to the start (0 offset), and sets the length to 0.

func (*Wrapper) SetReadWriterAt

func (wpr *Wrapper) SetReadWriterAt(rwa ReadWriterAt)

SetReadWriterAt lets you switch the underlying Read/WriterAt

func (*Wrapper) Write

func (wpr *Wrapper) Write(p []byte) (n int, err error)

Write writes p to the end of the Wrapper (at Len()), wrapping at Cap()

func (*Wrapper) WriteAt

func (wpr *Wrapper) WriteAt(p []byte, off int64) (n int, err error)

WriteAt writes p at the current offset+off, wrapping at Cap()

Jump to

Keyboard shortcuts

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