readfile

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFilemeta

func NewFilemeta(r reader.Reader, path string, offset int64) reader.Reader

New creates a new Encode reader from input reader by applying the given codec.

Types

type Config

type Config struct {
	Codec      encoding.Encoding
	BufferSize int
	Terminator LineTerminator
	MaxBytes   int
}

Config stores the configuration for the readers required to read a file line by line

type EncoderReader

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

Reader produces lines by reading lines from an io.Reader through a decoder converting the reader it's encoding to utf-8.

func NewEncodeReader

func NewEncodeReader(r io.ReadCloser, config Config) (EncoderReader, error)

New creates a new Encode reader from input reader by applying the given codec.

func (EncoderReader) Close

func (r EncoderReader) Close() error

func (EncoderReader) Next

func (r EncoderReader) Next() (reader.Message, error)

Next reads the next line from it's initial io.Reader This converts a io.Reader to a reader.reader

type FileMetaReader

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

Reader produces lines by reading lines from an io.Reader through a decoder converting the reader it's encoding to utf-8.

func (*FileMetaReader) Close

func (r *FileMetaReader) Close() error

func (*FileMetaReader) Next

func (r *FileMetaReader) Next() (reader.Message, error)

Next reads the next line from it's initial io.Reader This converts a io.Reader to a reader.reader

type LimitReader

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

Reader sets an upper limited on line length. Lines longer then the max configured line length will be snapped short.

func NewLimitReader

func NewLimitReader(r reader.Reader, maxBytes int) *LimitReader

New creates a new reader limiting the line length.

func (*LimitReader) Close

func (r *LimitReader) Close() error

func (*LimitReader) Next

func (r *LimitReader) Next() (reader.Message, error)

Next returns the next line.

type LineReader

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

LineReader reads lines from underlying reader, decoding the input stream using the configured codec. The reader keeps track of bytes consumed from raw input stream for every decoded line.

func NewLineReader

func NewLineReader(input io.ReadCloser, config Config) (*LineReader, error)

NewLineReader creates a new reader object

func (*LineReader) Close

func (r *LineReader) Close() error

func (*LineReader) Next

func (r *LineReader) Next() (b []byte, n int, err error)

Next reads the next line until the new line character. The return value b is the byte slice that contains the next line. The return value n is the number of bytes that were consumed from the underlying reader to read the next line. If the LineReader is configured with maxBytes n may be larger than the length of b due to skipped lines.

type LineTerminator

type LineTerminator uint8

LineTerminator is the option storing the line terminator characters Supported newline reference: https://en.wikipedia.org/wiki/Newline#Unicode

const (
	// InvalidTerminator is the invalid terminator
	InvalidTerminator LineTerminator = iota
	// AutoLineTerminator accepts both LF and CR+LF
	AutoLineTerminator
	// LineFeed is the unicode char LF
	LineFeed
	// VerticalTab is the unicode char VT
	VerticalTab
	// FormFeed is the unicode char FF
	FormFeed
	// CarriageReturn is the unicode char CR
	CarriageReturn
	// CarriageReturnLineFeed is the unicode chars CR+LF
	CarriageReturnLineFeed
	// NextLine is the unicode char NEL
	NextLine
	// LineSeparator is the unicode char LS
	LineSeparator
	// ParagraphSeparator is the unicode char PS
	ParagraphSeparator
	// NullTerminator
	NullTerminator
)

func (*LineTerminator) Unpack

func (l *LineTerminator) Unpack(option string) error

Unpack unpacks the configuration from the config file

type StripNewline

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

StripNewline reader removes the last trailing newline characters from read lines.

func NewStripNewline

func NewStripNewline(r reader.Reader, terminator LineTerminator) *StripNewline

New creates a new line reader stripping the last tailing newline.

func (*StripNewline) Close

func (p *StripNewline) Close() error

func (*StripNewline) Next

func (p *StripNewline) Next() (reader.Message, error)

Next returns the next line.

type TimeoutReader

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

TimeoutReader will signal some configurable timeout error if no new line can be returned in time.

func NewTimeoutReader

func NewTimeoutReader(reader reader.Reader, signal error, t time.Duration) *TimeoutReader

NewTimeoutReader returns a new timeout reader from an input line reader.

func (*TimeoutReader) Close

func (r *TimeoutReader) Close() error

func (*TimeoutReader) Next

func (r *TimeoutReader) Next() (reader.Message, error)

Next returns the next line. If no line was returned before timeout, the configured timeout error is returned. For handline timeouts a goroutine is started for reading lines from configured line reader. Only when underlying reader returns an error, the goroutine will be finished.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳