input

package
v0.0.0-...-7534ea8 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2022 License: MIT Imports: 2 Imported by: 2

Documentation

Overview

Package input defines data types and functions for managing input data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromReader

func FromReader(r io.Reader) io.ReaderAt

FromReader converts an io.Reader to an io.ReaderAt.

func Slice

func Slice(r io.ReaderAt, low, high int) []byte

Slice returns the slice [low:high) in the given ReaderAt.

Types

type Input

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

Input represents the input data and is an efficient wrapper of io.ReaderAt which provides a nicer API, avoids repeated interface function calls, and uses a cache for buffered reading. An Input also tracks the index of the furthest byte that has been read.

func NewInput

func NewInput(r io.ReaderAt) *Input

NewInput creates a new Input wrapper for the io.ReaderAt.

func (*Input) Advance

func (i *Input) Advance(n int) bool

Advance moves the offset forward by 'n' bytes. Returns true if the advance was successful (n chars were successfully skipped) and false otherwise. Note that even if Advance returns true the next call to Peek may return false if the advance went to the exact end of the data.

func (*Input) Furthest

func (i *Input) Furthest() int

Furthest returns the furthest read position.

func (*Input) Peek

func (i *Input) Peek() (byte, bool)

Peek returns the next byte in the stream or 'false' if there are no more bytes. Successive calls to Peek will return the same value unless there is a call to SeekTo or Advance in between.

func (*Input) PeekBefore

func (i *Input) PeekBefore() (byte, bool)

func (*Input) Pos

func (i *Input) Pos() int

Pos returns the current read position.

func (*Input) ReadAt

func (i *Input) ReadAt(b []byte, pos int64) (n int, err error)

func (*Input) ResetFurthest

func (i *Input) ResetFurthest()

ResetFurthest resets the furthest read tracker to zero.

func (*Input) SeekTo

func (i *Input) SeekTo(pos int) bool

SeekTo moves the current read position to the desired read position. Returns true if the seek went to a valid location within the reader, and false otherwise. In other words, if seek returns true the next call to Peek will return a valid byte.

func (*Input) Slice

func (i *Input) Slice(low, high int) []byte

Slice returns a slice of the reader corresponding to the range [low:high).

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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