io

package
v0.0.0-...-d8ac9bd Latest Latest
Warning

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

Go to latest
Published: May 18, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ScanStxEtxCombiRecord

func ScanStxEtxCombiRecord(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanStxEtxCombiRecord is a bufio.SplitFunc which can handle a mix of plain lines and STX-ETX records. This is used instead of ScanStxEtcRecord or bufio.ScanLines if the content can be mixed.

e.g. a log file was originally plain lines then changed to STX-ETX record format.

The tokens

func ScanStxEtxRecord

func ScanStxEtxRecord(data []byte, atEOF bool) (advance int, token []byte, err error)

ScanStxEtxRecord is a bufio.SplitFunc with looks for a record which is within an STX (0x02) and ETX (0x03) characters

Types

type LineWriter

type LineWriter func(s string) error

type Reader

type Reader func(r io.Reader) error

func NewReader

func NewReader(r ...Reader) Reader

func (Reader) Decompress

func (a Reader) Decompress() Reader

func (Reader) DecompressIf

func (a Reader) DecompressIf(p bool) Reader

func (Reader) ForEach

func (a Reader) ForEach(splitFunc bufio.SplitFunc, handler ReaderHandler) Reader

ForEach will call a ReaderHandler function for each token returned by a bufio.Scanner running over the file. The scanner will use the supplied bufio.SplitFunc to determine the token's passed to the ReaderHandler.

func (Reader) ForEachLine

func (a Reader) ForEachLine(handler ReaderHandler) Reader

ForEachLine will call a ReaderHandler function for each lf or crlf terminated line from the file.

This is shorthand for Reader.ForEach(bufio.ScanLines, handler)

func (Reader) ForEachRecord

func (a Reader) ForEachRecord(handler ReaderHandler) Reader

ForEachRecord will call a ReaderHandler function for each STX-ETX delimited record from the file.

This is shorthand for Reader.ForEach(ScanStxEtxRecord, handler)

func (Reader) FromBytes

func (a Reader) FromBytes(b []byte) error

func (Reader) Gob

func (a Reader) Gob(e any) Reader

Gob will read a struct/value from the reader using the encoding/gob package.

func (Reader) Json

func (a Reader) Json(e any) Reader

func (Reader) Open

func (a Reader) Open(filename string) error

Open a file and pass to the Reader

func (Reader) Read

func (a Reader) Read(r io.Reader) error

func (Reader) Then

func (a Reader) Then(b Reader) Reader

func (Reader) Xml

func (a Reader) Xml(e any) Reader

func (Reader) Yaml

func (a Reader) Yaml(e any) Reader

type ReaderHandler

type ReaderHandler func(string) error

ReaderHandler accepts a line or record from a Reader

type Writer

type Writer func(io.Writer) error

Writer writes data to an io.Writer

func NewWriter

func NewWriter(w ...Writer) Writer

NewWriter creates a new writer

func (Writer) Compress

func (a Writer) Compress() Writer

Compress will compress using gzip

func (Writer) CompressIf

func (a Writer) CompressIf(p bool) Writer

func (Writer) CreateBytes

func (a Writer) CreateBytes() ([]byte, error)

func (Writer) CreateFile

func (a Writer) CreateFile(filename string) error

CreateFile creates a file using the writer

func (Writer) Gob

func (a Writer) Gob(e any) Writer

Gob will write a struct/value to the writer using the encoding/gob package.

func (Writer) Then

func (a Writer) Then(b Writer) Writer

Then chains two Writers.

func (Writer) Write

func (a Writer) Write(w io.Writer) error

func (Writer) WriteLines

func (a Writer) WriteLines(w WriterHandler) Writer

WriteLines will call a WriterHandler and each line written to the handler will be terminated with a Line Feed.

func (Writer) WriteRecords

func (a Writer) WriteRecords(w WriterHandler) Writer

WriteRecords will call a WriterHandler and each line written to the handler will be wrapped with a stx/etx pair.

type WriterHandler

type WriterHandler func(w LineWriter) error

WriterHandler is a function called by WriteLines when writing Lines or WriteRecords when writing Records

Jump to

Keyboard shortcuts

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