Documentation
¶
Overview ¶
Package bigcsv provides a simple API for processing large CSV data.
It offers loading CSV via HTTP or the filesystem with gzip detection, or directly from an io.Reader.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrOnData = errors.New("OnData error")
ErrOnData is passed to OnError when OnData returns an error.
var ErrOnRow = errors.New("OnRow error")
ErrOnRow is passed to OnError when OnRow returns an error.
var ErrParse = errors.New("Parse error")
ErrParse is passed to OnError when Parse returns an error.
Functions ¶
This section is empty.
Types ¶
type FileStream ¶
type FileStream string
FileStream provides a reader for CSV processing from the filesystem.
FileStream will automatically decompress *.gz as gzip files. Everything else will be treated as a CSV.
func (FileStream) Open ¶
func (fs FileStream) Open() (io.ReadCloser, error)
type HTTPStream ¶
type HTTPStream string
HTTPStream provides a reader for the CSV stream directly via HTTP(s).
func (HTTPStream) Open ¶
func (hs HTTPStream) Open() (io.ReadCloser, error)
type Parser ¶
type Parser[T any] struct { // Reader is the CSV reader which can be modified prior to processing. // // To change CSV settings, use the Reader directly after creating the Parser // and prior to calling Run Reader *csv.Reader // OnRow accepts a CSV row prior to parsing. // // If an error is returned, the OnError function is called and the row is // skipped. OnRow func(row []string) error // Parse should parse the raw row from the CSV and return the data type. Parse func(row []string) (T, error) // OnData accepts a processed CSV row as a Report. // // The return value signals whether to stop ALL further processing. Note // that when using multiple workers, already started workers will continue // to process their row until this signal is received. OnData func(data T) error // OnError handles errors arising during processing. // // If the Parse method returns an error, this method will receive it. // Other, errors from the underlying *csv.Reader will be passed here, too. OnError func(error) // contains filtered or unexported fields }
Parser provides streaming CSV parsing. It must be created with New.
type Stream ¶
type Stream interface {
Open() (io.ReadCloser, error)
}
Stream is the interface which provides a CSV file to process.
func ReadStream ¶
ReadStream provides an adapter for any io.Reader.
If the reader is no also an io.Closer, it will be wrapped using io.NopCloser.