Documentation ¶
Overview ¶
seekable byte buffer package
seekable byte buffer package
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrWrite error = errors.New("Unable to write all bytes")
Functions ¶
This section is empty.
Types ¶
type ReadBuf ¶
type ReadBuf struct {
// contains filtered or unexported fields
}
ReadBuf implements the Reader interface. It wraps a bytes.Buffer but allows relative Skips (forward) and absolute Seeks (forward and backwards).
func NewReadBuffer ¶
Constructor for creating a new ReadBuf. bs is the underlying byte array to read from.
func (*ReadBuf) Capacity ¶
FullLen returns the number of bytes in the original byte slice regardless of current read position.
func (*ReadBuf) Read ¶
Read reads the next len(p) bytes from the buffer or until the buffer is drained. The return value n is the number of bytes read. If the buffer has no data to return, err is io.EOF (unless len(p) is zero); otherwise it is nil.
func (*ReadBuf) Seek ¶
Seek to an absolute position in the underlying byte array regardless of what part of the buffer has been read so far.
If n is beyond the end of the underlying byte array, this method will panic.
func (*ReadBuf) Skip ¶
Skip forward the specified number of bytes. n is interpreted as relative to the unread portion of the slice. You cannot skip backwards. To do that use the Seek method.
If n is beyond the end of the underlying byte array, this method will NOT panic. Instead, the next read will just return EOF.
func (*ReadBuf) UnreadByte ¶
UnreadByte unreads the last byte returned by the most recent read operation. If write has happened since the last read, UnreadByte returns an error.
type WriteBuf ¶
type WriteBuf struct {
// contains filtered or unexported fields
}
WriteBuf implements the Writer interface. It is a Writer that allows relative Skips (forward) and absolute Seeks (forward and backwards).
func NewWriteBuffer ¶
Constructor for creating a new WriteBuf. capacity sets the initial internal byte slice capacity.
func (*WriteBuf) Bytes ¶
Bytes returns a reference to the underlying byte array truncated to the last written byte. Any subsequent changes to the byte slice returned will silently change the slice held by this buffer (unless a reallocation and copy is done to increase the size).
func (*WriteBuf) Capacity ¶
Capacity returns the number of bytes in the original byte slice regardless of current write position.
func (*WriteBuf) Reset ¶
func (b *WriteBuf) Reset()
Resets internal pointers to forget any data already written to the buffer. A new underlying byte array is NOT created so any new writes may modify the slice you received if you previously called the Bytes() method.
func (*WriteBuf) Seek ¶
Seek to an absolute position in the underlying byte array regardless of what part of the buffer has been read so far.
If n is beyond the end of the underlying byte array, the buffer size capacity will be increased.
func (*WriteBuf) Skip ¶
Skip moves ahead a relative n bytes from the current offset, which is determined as the end of the last write or the last Seek position, if that was the most recent operation. If n + currOffset is larger than the capacity of the underlying byte array, the buffer size capacity will be increased.
func (*WriteBuf) Write ¶
Write writes len(p) bytes from p to the underlying data stream. It returns the number of bytes written from p (0 <= n <= len(p)) and any error encountered that caused the write to stop early. Write must return a non-nil error if it returns n < len(p). Write must not modify the slice data, even temporarily.