Documentation
¶
Overview ¶
Package reader loads tabular data files into frames. Each supported file format registers itself in the format registry via init().
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SupportedFormats ¶
func SupportedFormats() []string
SupportedFormats lists registered format names, sorted.
Types ¶
type Format ¶
type Format string
Format names a supported input format.
const ( FormatDSV Format = "dsv" FormatCSV Format = "csv" FormatTSV Format = "tsv" FormatJSON Format = "json" FormatJSONL Format = "jsonl" FormatParquet Format = "parquet" FormatFWF Format = "fwf" FormatSQLite Format = "sqlite" FormatExcel Format = "excel" FormatLogfmt Format = "logfmt" FormatMarkdown Format = "markdown" FormatHTML Format = "html" )
func Detect ¶
Detect guesses the format from a file name; empty string when unknown. For URLs the query string and fragment are ignored, so presigned or tokenized links like "https://host/data.csv?token=..." still detect.
type NamedFrame ¶
type NamedFrame struct {
Name string // tab title, e.g. file stem or sheet/table name
Frame *data.Frame
}
NamedFrame is one table loaded from a source; multi-table sources (spreadsheets, database files) produce several.
type Options ¶
type Options struct {
Format Format
Separator rune // dsv field separator (default ',')
Quote rune // dsv quote char (default '"')
NoHeader bool // first row is data, synthesize column names
IgnoreErrors bool // drop unparsable rows instead of failing
InferSchema InferMode // default InferSafe
InferTypes []string // subset of: int float boolean date datetime, or "all"
TruncateRagged bool // truncate rows longer than the header
Widths []int // fwf column widths ([] = auto-detect)
SeparatorLength int // fwf separator width (default 1)
FlexibleWidth bool // fwf: allow last column to overflow
Key string // decryption key for encrypted database files
}
Options carries all parsing knobs; format readers pick what applies.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the option defaults shared by all formats.
type Reader ¶
type Reader interface {
// Read consumes the source and returns one or more frames.
Read(src *Source, opt Options) ([]NamedFrame, error)
}
Reader parses one format.
type Source ¶
type Source struct {
// Path is the original user-supplied location (file path or URL).
Path string
// LocalPath is the on-disk file to read. For plain files it equals Path;
// for stdin and URLs it points at a temporary spool file.
LocalPath string
// Stdin marks input piped from standard input ("-").
Stdin bool
// URL marks input downloaded from http(s).
URL bool
}
Source is one input to load: a local file, standard input, or a URL that has already been downloaded to a temporary file.
func FromURL ¶
FromURL downloads an http(s) URL to a temporary file and wraps it in a Source. Redirects are followed; the request carries a plain user agent.
func (*Source) Cleanup ¶
func (s *Source) Cleanup()
Cleanup removes the temporary spool file backing a stdin or URL source. It is a no-op for plain local files. Safe to call once every reader is done: readers fully materialize their frames before returning.