processor

package
v0.0.0-...-76447f0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConcurrentAccessErr = errors.New("file has been modified since the tail reader was opened")

ConcurrentAccessErr indicates that a file has been modified while the tail reader was reading it

View Source
var ReverseScanLines = func(data []byte, atEOF bool) (advance int, token []byte, err error) {
	n := len(data) - 1
	for i := n; i >= 0; i-- {
		c := data[i]
		if c == '\n' {

			return advance + 1, data[n+1-advance : n+1], nil
		} else {
			advance++
		}
	}
	if atEOF {
		return advance, data[:n+1], nil
	}
	return 0, nil, nil
}

ReverseScanLines is similar to bufio.ScanLines except that it scans the bytes from right to left

Functions

This section is empty.

Types

type EventBreaker

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

EventBreaker is responsible to identify events in an array of bytes read from a io.Reader

func NewEventBreaker

func NewEventBreaker(reader TailReader, splitter bufio.SplitFunc, bufferSize int) *EventBreaker

NewEventBreaker creates a new EventBreaker that reads from the passed TailReader with a buffer of the given bufferSize. It generates events by applying the passed bufio.SplitFunc.

func (*EventBreaker) Next

func (eb *EventBreaker) Next() (string, error)

Next implements EventProcessor contract

type EventFilter

type EventFilter func(string) bool

EventFilter verifies that an event matches a condition. It returns true if the event passes the check

type EventProcessor

type EventProcessor interface {
	// Next returns an event as a string. It returns io.EOF if no more event will be returned
	Next() (string, error)
}

EventProcessor defines an iterator that process an event

func WithFilter

func WithFilter(processor EventProcessor, filter EventFilter) EventProcessor

WithFilter decorates an EventProcessor to apply a predicate that must validate the event to return it

func WithLimit

func WithLimit(processor EventProcessor, limit uint) EventProcessor

WithLimit decorates an EventProcessor to apply a limit on the maximum number of events that it can return

type TailReader

type TailReader interface {
	io.Reader
	io.Closer
	// SeekToEnd updates the offset of the TailReader towards the end of file. It basically rewinds the reader by the given
	// offset.
	SeekToEnd(offset uint32)
}

TailReader reads a file from the end to the start of the file. Once created if the file is modified, the next Read call will return an error.

func NewTailReader

func NewTailReader(fs afero.Fs, name string) (TailReader, error)

NewTailReader creates a tailReader for the given file in parameters

Jump to

Keyboard shortcuts

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