core

package
v0.0.0-...-84e4751 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package core implements the CSV decoding and encoding primitives shared by the CSV module wrappers.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeaderColumnConflict = errors.New("csv: cannot specify both header: true and columns option")

ErrHeaderColumnConflict reports that both a header row and explicit columns were requested at the same time.

Functions

func ConvertValue

func ConvertValue(raw string, opts Options) runtime.Value

ConvertValue converts a decoded CSV field to the runtime representation requested by opts.

func Decode

func Decode(ctx context.Context, data runtime.String, opts Options) (runtime.Value, error)

Decode eagerly decodes CSV text into an array of objects.

func DecodeRows

func DecodeRows(ctx context.Context, data runtime.String, opts Options) (runtime.Value, error)

DecodeRows eagerly decodes CSV text into an array of row arrays.

func ResolveContent

func ResolveContent(input runtime.Value) (runtime.String, error)

ResolveContent normalizes supported CSV content input to a runtime.String. It accepts only runtime.String and runtime.Binary values.

func ResolveHeaders

func ResolveHeaders(firstRow []string, opts Options) ([]string, bool, error)

ResolveHeaders returns the headers to use for object decoding, whether the first row was consumed as a header row, and any validation error.

Types

type DecodeIterator

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

DecodeIterator iterates over decoded CSV objects. The iterator key is the original 1-based CSV record number after parsing.

func NewDecodeIterator

func NewDecodeIterator(data runtime.String, opts Options) (*DecodeIterator, error)

NewDecodeIterator returns an iterator over decoded CSV objects.

func (*DecodeIterator) Iterate

Iterate returns the iterator itself.

func (*DecodeIterator) Next

Next returns the next decoded object and its CSV record number.

type DecodeRowsIterator

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

DecodeRowsIterator iterates over decoded CSV rows. The iterator key is the original 1-based CSV record number after parsing.

func NewDecodeRowsIterator

func NewDecodeRowsIterator(data runtime.String, opts Options) (*DecodeRowsIterator, error)

NewDecodeRowsIterator returns an iterator over decoded CSV rows.

func (*DecodeRowsIterator) Iterate

Iterate returns the iterator itself.

func (*DecodeRowsIterator) Next

Next returns the next decoded row and its CSV record number.

type EncodeResult

type EncodeResult struct {
	// Text is the encoded CSV output.
	Text string
	// Rows is the number of data rows written, excluding any generated header.
	Rows int
}

EncodeResult contains the encoded CSV text and the number of data rows written.

func Encode

func Encode(ctx context.Context, data runtime.Value, opts Options) (*EncodeResult, error)

Encode encodes an array of objects or row arrays into CSV text.

type Error

type Error struct {
	Err    error
	Msg    string
	Row    int
	Column int
}

Error reports a CSV-specific error with optional row and column context.

func (*Error) Error

func (e *Error) Error() string

Error formats the CSV error message with row and optional column metadata.

func (*Error) Unwrap

func (e *Error) Unwrap() error

Unwrap returns the underlying wrapped error.

type Options

type Options struct {
	Delimiter  string   `json:"delimiter"`
	Comment    string   `json:"comment"`
	Columns    []string `json:"columns"`
	NullValues []string `json:"nullValues"`
	Header     bool     `json:"header"`
	Trim       bool     `json:"trim"`
	SkipEmpty  bool     `json:"skipEmpty"`
	Strict     bool     `json:"strict"`
	InferTypes bool     `json:"inferTypes"`
}

Options configures CSV decoding and encoding behavior.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default CSV options used by the module.

func (*Options) ApplyToReader

func (o *Options) ApplyToReader(r *csv.Reader) error

ApplyToReader applies the reader-supported options to r.

func (*Options) ApplyToWriter

func (o *Options) ApplyToWriter(w *csv.Writer) error

ApplyToWriter applies the writer-supported options to w.

Jump to

Keyboard shortcuts

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