peekabuf

package module
Version: v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2020 License: MIT Imports: 3 Imported by: 0

README

Peek-A-Buf

Peek-A-Buf is a Go library for a buffered reader with side effect free peeking capability.

At the moment, a buffered reader for runes is implemented meant for things like scanners.

Why is this useful if bufio.Reader exists? Well, the Peek function is sadly not side effect free there:

Calling Peek prevents a UnreadByte or UnreadRune call from succeeding until the next read operation.

But this was something needed to fix a bug in the SQLDumpSplitter3. So I created this little library basically wrapping bufio.Reader and re-implementing small parts of it.

In addition to the side effect free peek function, it returns an EOF rune instead of an error if it reaches the end of the buffer.

Have a look at the documentation.

Installation

Just go get it:

go get github.com/philiplb/peekabuf

License

MIT

Documentation

Overview

Package peekabuf offers buffers with the capability to be peeked without side effects on the unread functionality. Along with that, it returns a special `EOF` rune instead of an error if it reaches the end of the buffer.

Index

Constants

View Source
const EOF = rune(-1)

EOF is a special rune indicating the end of the buffer.

Variables

This section is empty.

Functions

This section is empty.

Types

type RuneReader

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

RuneReader is a buffered reader which operates on runes.

func NewRuneReader

func NewRuneReader(reader io.Reader) *RuneReader

NewRuneReader creates a new instance of a RuneReader.

func (*RuneReader) Peek

func (rr *RuneReader) Peek(n uint) ([]rune, error)

Peek returns the desired amount of runes without removing them from the buffer. If there are not enough runes in the buffer, it returns as many as possible with an EOF rune at the end.

func (*RuneReader) Read

func (rr *RuneReader) Read() rune

Read reads and removes the next rune from the buffer and returns it. If there are no runes left in the buffer, it returns an EOF.

func (*RuneReader) Unread

func (rr *RuneReader) Unread()

Unread puts back the last read rune to the front of the buffer. It reverts the Read function. If there was no call to Read, it can't unread the rune and the call to this function is a no op.

Source Files

Jump to

Keyboard shortcuts

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