obuf

package
v1.0.0-...-26db8b9 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2015 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

seekable byte buffer package

seekable byte buffer package

Index

Constants

This section is empty.

Variables

View Source
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

func NewReadBuffer(bs []byte) *ReadBuf

Constructor for creating a new ReadBuf. bs is the underlying byte array to read from.

func (*ReadBuf) Capacity

func (b *ReadBuf) Capacity() int

FullLen returns the number of bytes in the original byte slice regardless of current read position.

func (*ReadBuf) Len

func (b *ReadBuf) Len() int

Len returns the number of bytes of the unread portion of the slice

func (*ReadBuf) Read

func (b *ReadBuf) Read(p []byte) (n int, err error)

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

func (b *ReadBuf) Seek(n uint)

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

func (b *ReadBuf) Skip(n uint)

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

func (b *ReadBuf) UnreadByte() error

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

func NewWriteBuffer(capacity int) *WriteBuf

Constructor for creating a new WriteBuf. capacity sets the initial internal byte slice capacity.

func (*WriteBuf) Bytes

func (b *WriteBuf) Bytes() []byte

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

func (b *WriteBuf) Capacity() int

Capacity returns the number of bytes in the original byte slice regardless of current write position.

func (*WriteBuf) Len

func (b *WriteBuf) Len() int

Len returns the number of bytes written to the buffer

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

func (b *WriteBuf) Seek(n uint)

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

func (b *WriteBuf) Skip(n uint)

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

func (b *WriteBuf) Write(p []byte) (n int, err error)

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.

func (*WriteBuf) WriteByte

func (wb *WriteBuf) WriteByte(b byte) error

WriteByte writes a single byte to the underlying byte slice. If the byte slice is not large enough a new one will be allocated. nil error is always returned, since no error is possible in this operation, so error can be safely ignored from this method.

Jump to

Keyboard shortcuts

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