goproxy: github.com/elazarl/goproxy/regretable Index | Files

package regretable

import "github.com/elazarl/goproxy/regretable"

Index

Package Files

regretreader.go

type RegretableReader Uses

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 Uses

func NewRegretableReader(r io.Reader) *RegretableReader

initialize a RegretableReader with underlying reader r

func NewRegretableReaderSize Uses

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

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

func (*RegretableReader) Forget Uses

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 Uses

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 Uses

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 Uses

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

Same as RegretableReader, but allows closing the underlying reader

func NewRegretableReaderCloser Uses

func NewRegretableReaderCloser(rc io.ReadCloser) *RegretableReaderCloser

initialize a RegretableReaderCloser with underlying readCloser rc

func NewRegretableReaderCloserSize Uses

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

initialize a RegretableReaderCloser with underlying readCloser rc

func (*RegretableReaderCloser) Close Uses

func (rbc *RegretableReaderCloser) Close() error

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

Package regretable imports 1 packages (graph) and is imported by 17 packages. Updated 2018-07-29. Refresh now. Tools for package owners.