Documentation ¶
Index ¶
- Variables
- type Builder
- func (b *Builder) ByteAt(i int) (byte, error)
- func (b *Builder) Bytes() []byte
- func (b *Builder) Grow(n int)
- func (b *Builder) Insert(i int, p []byte) (n int, err error)
- func (b *Builder) InsertString(i int, p string) (n int, err error)
- func (b *Builder) Len() int
- func (b *Builder) Next(n int) []byte
- func (b *Builder) Read(p []byte) (n int, err error)
- func (b *Builder) ReadByte() (c byte, err error)
- func (b *Builder) ReadBytes(delim byte) (line []byte, err error)
- func (b *Builder) ReadFrom(r io.Reader) (n int64, err error)
- func (b *Builder) ReadRune() (r rune, size int, err error)
- func (b *Builder) ReadString(delim byte) (line string, err error)
- func (b *Builder) Reset()
- func (b *Builder) ResetWith(buf []byte) (n int, err error)
- func (b *Builder) ResetWithString(s string) (n int, err error)
- func (b *Builder) String() string
- func (b *Builder) Truncate(n int)
- func (b *Builder) UnreadByte() error
- func (b *Builder) UnreadRune() error
- func (b *Builder) Write(p []byte) (n int, err error)
- func (b *Builder) WriteByte(c byte) error
- func (b *Builder) WriteRune(r rune) (n int, err error)
- func (b *Builder) WriteString(s string) (n int, err error)
- func (b *Builder) WriteTo(w io.Writer) (n int64, err error)
Constants ¶
This section is empty.
Variables ¶
var ErrFailedToGrow = errors.New("insertablebuffer.Buf: failed to grow buffer enough")
var ErrInvalidIndex = errors.New("insertablebuffer.Buf: invalid index")
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
A Buffer is a variable-sized buffer of bytes with Read and Write methods. The zero value for Buffer is an empty buffer ready to use.
func NewBuilder ¶
NewBuilder creates and initializes a new Buffer using buf as its initial contents. It is intended to prepare a Buffer to read existing data. It can also be used to size the internal buffer for writing. To do that, buf should have the desired capacity but a length of zero.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func NewBuilderString ¶
NewBuilderString creates and initializes a new Buffer using string s as its initial contents. It is intended to prepare a buffer to read an existing string.
In most cases, new(Buffer) (or just declaring a Buffer variable) is sufficient to initialize a Buffer.
func (*Builder) ByteAt ¶
ByteAt returns the byte at the given index. It returns ErrInvalidIndex if the given index is outside the buffer's length. There is no RuneAt currently, for I'm unsure what the desired behaviour should be (read rune by rune until we get to the ith rune, read the rune starting at i).
func (*Builder) Bytes ¶
Bytes returns a slice of the contents of the unread portion of the buffer; len(b.Bytes()) == b.Len(). If the caller changes the contents of the returned slice, the contents of the buffer will change provided there are no intervening method calls on the Buffer.
func (*Builder) Grow ¶
Grow grows the buffer's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to the buffer without another allocation. If n is negative, Grow will panic. If the buffer can't grow it will panic with ErrTooLarge.
func (*Builder) Insert ¶
Insert inserts the buffer at the desired position, growing the buffer as necessary. If i is less than zero, or greater than len(p), an error is returned.
func (*Builder) InsertString ¶
InsertString inserts the string at the desired position, growing the buffer as necessary. If i is less than zero, or greater than len(p), an error is returned.
func (*Builder) Len ¶
Len returns the number of bytes of the unread portion of the buffer; b.Len() == len(b.Bytes()).
func (*Builder) Next ¶
Next returns a slice containing the next n bytes from the buffer, advancing the buffer as if the bytes had been returned by Read. If there are fewer than n bytes in the buffer, Next returns the entire buffer. The slice is only valid until the next call to a read or write method.
func (*Builder) 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 (*Builder) ReadByte ¶
ReadByte reads and returns the next byte from the buffer. If no byte is available, it returns error io.EOF.
func (*Builder) ReadBytes ¶
ReadBytes reads until the first occurrence of delim in the input, returning a slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadBytes returns err != nil if and only if the returned data does not end in delim.
func (*Builder) ReadFrom ¶
ReadFrom reads data from r until EOF and appends it to the buffer, growing the buffer as needed. The return value n is the number of bytes read. Any error except io.EOF encountered during the read is also returned. If the buffer becomes too large, ReadFrom will panic with ErrTooLarge.
func (*Builder) ReadRune ¶
ReadRune reads and returns the next UTF-8-encoded Unicode code point from the buffer. If no bytes are available, the error returned is io.EOF. If the bytes are an erroneous UTF-8 encoding, it consumes one byte and returns U+FFFD, 1.
func (*Builder) ReadString ¶
ReadString reads until the first occurrence of delim in the input, returning a string containing the data up to and including the delimiter. If ReadString encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF). ReadString returns err != nil if and only if the returned data does not end in delim.
func (*Builder) Reset ¶
func (b *Builder) Reset()
Reset resets the buffer so it has no content. b.Reset() is the same as b.Truncate(0).
func (*Builder) String ¶
String returns the contents of the unread portion of the buffer as a string. If the Buffer is a nil pointer, it returns "<nil>".
func (*Builder) Truncate ¶
Truncate discards all but the first n unread bytes from the buffer. It panics if n is negative or greater than the length of the buffer.
func (*Builder) 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.
func (*Builder) UnreadRune ¶
UnreadRune unreads the last rune returned by ReadRune. If the most recent read or write operation on the buffer was not a ReadRune, UnreadRune returns an error. (In this regard it is stricter than UnreadByte, which will unread the last byte from any read operation.)
func (*Builder) Write ¶
Write appends the contents of p to the buffer, growing the buffer as needed. The return value n is the length of p; err is always nil. If the buffer becomes too large, Write will panic with ErrTooLarge.
func (*Builder) WriteByte ¶
WriteByte appends the byte c to the buffer, growing the buffer as needed. The returned error is always nil, but is included to match bufio.Writer's WriteByte. If the buffer becomes too large, WriteByte will panic with ErrTooLarge.
func (*Builder) WriteRune ¶
WriteRune appends the UTF-8 encoding of Unicode code point r to the buffer, returning its length and an error, which is always nil but is included to match bufio.Writer's WriteRune. The buffer is grown as needed; if it becomes too large, WriteRune will panic with ErrTooLarge.
func (*Builder) WriteString ¶
WriteString appends the contents of s to the buffer, growing the buffer as needed. The return value n is the length of s; err is always nil. If the buffer becomes too large, WriteString will panic with ErrTooLarge.