langos

package
v0.5.9-0...-ba7202b Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferedReadSeeker

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

BufferedReadSeeker wraps bufio.Reader to expose Seek method from the provided io.ReadSeeker in NewBufferedReadSeeker.

func NewBufferedReadSeeker

func NewBufferedReadSeeker(readSeeker io.ReadSeeker, size int) BufferedReadSeeker

NewBufferedReadSeeker creates a new instance of BufferedReadSeeker, out of io.ReadSeeker. Argument `size` is the size of the read buffer.

func (BufferedReadSeeker) Read

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

Read reads to the byte slice from from buffered reader.

func (BufferedReadSeeker) ReadAt

func (b BufferedReadSeeker) ReadAt(p []byte, off int64) (n int, err error)

ReadAt implements io.ReaderAt if the provided ReadSeeker also implements it, otherwise it returns no error and no bytes read.

func (BufferedReadSeeker) Seek

func (b BufferedReadSeeker) Seek(offset int64, whence int) (int64, error)

Seek moves the read position of the underlying ReadSeeker and resets the buffer.

type Langos

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

Langos is a reader with a lookahead peekBuffer this is the most naive implementation of a lookahead peekBuffer it should issue a lookahead Read when a Read is called, hence the name - langos |--->====>>------------|

cur   topmost

the first read is not a lookahead but the rest are so, it could be that a lookahead read might need to wait for a previous read to finish due to resource pooling

All Read and Seek method call must be synchronous.

func NewLangos

func NewLangos(r Reader, peekSize int) *Langos

NewLangos bakes a new yummy langos that peeks on provided reader when its Read method is called. Argument peekSize defines the length of peeks.

func (*Langos) Close

func (l *Langos) Close() (err error)

Close unblocks Read method calls that are waiting for peek to finish.

func (*Langos) Read

func (l *Langos) Read(p []byte) (n int, err error)

Read copies the data to the provided byte slice starting from the current read position. The first read will wait for the underlaying Reader to return all the data and start a peek on the next data segment. All sequential reads will wait for peek to finish reading the data. If the current peek is not finished when Read is called, a second peek will be started to apprehend the following Read call.

func (*Langos) ReadAt

func (l *Langos) ReadAt(p []byte, off int64) (int, error)

ReadAt reads the data on offset and does not add any optimizations.

func (*Langos) Seek

func (l *Langos) Seek(offset int64, whence int) (int64, error)

Seek moves the Read cursor to a specific position.

type Reader

type Reader interface {
	io.ReadSeeker
	io.ReaderAt
}

Reader contains all methods that Langos needs to read data from.

func NewBufferedLangos

func NewBufferedLangos(r Reader, bufferSize int) Reader

NewBufferedLangos wraps a new Langos with BufferedReadSeeker and returns it.

Jump to

Keyboard shortcuts

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