regretable

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2016 License: BSD-3-Clause, Apache-2.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RegretableReader

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

A RegretableReader will allow you to read from a reader, and then to "regret" reading it, and push back everything you've read. For example,

rb := NewRegretableReader(bytes.NewBuffer([]byte{1,2,3}))
var b = make([]byte,1)
rb.Read(b) // b[0] = 1
rb.Regret()
ioutil.ReadAll(rb.Read) // returns []byte{1,2,3},nil

func NewRegretableReader

func NewRegretableReader(r io.Reader) *RegretableReader

initialize a RegretableReader with underlying reader r

func NewRegretableReaderSize

func NewRegretableReaderSize(r io.Reader, size int) *RegretableReader

initialize a RegretableReader with underlying reader r, whose buffer is size bytes long

func (*RegretableReader) Forget

func (rb *RegretableReader) Forget()

Will "forget" everything read so far.

rb := NewRegretableReader(bytes.NewBuffer([]byte{1,2,3}))
var b = make([]byte,1)
rb.Read(b) // b[0] = 1
rb.Forget()
rb.Read(b) // b[0] = 2
rb.Regret()
ioutil.ReadAll(rb.Read) // returns []byte{2,3},nil

func (*RegretableReader) Read

func (rb *RegretableReader) Read(p []byte) (n int, err error)

reads from the underlying reader. Will buffer all input until Regret is called.

func (*RegretableReader) Regret

func (rb *RegretableReader) Regret()

The next read from the RegretableReader will be as if the underlying reader was never read (or from the last point forget is called).

type RegretableReaderCloser

type RegretableReaderCloser struct {
	RegretableReader
	// contains filtered or unexported fields
}

Same as RegretableReader, but allows closing the underlying reader

func NewRegretableReaderCloser

func NewRegretableReaderCloser(rc io.ReadCloser) *RegretableReaderCloser

initialize a RegretableReaderCloser with underlying readCloser rc

func NewRegretableReaderCloserSize

func NewRegretableReaderCloserSize(rc io.ReadCloser, size int) *RegretableReaderCloser

initialize a RegretableReaderCloser with underlying readCloser rc

func (*RegretableReaderCloser) Close

func (rbc *RegretableReaderCloser) Close() error

Closes the underlying readCloser, you cannot regret after closing the stream

Jump to

Keyboard shortcuts

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