Documentation ¶
Overview ¶
Package formats describes the supported data input/output formats. The goal of this package is to support iteration of records (containing fields) within any data set:
+----------------------------+ | Data Set | | +------------------------+ | | | Record 1 | | | | Field 1 | Field 2| ... | | | +------------------------+ | | +------------------------+ | | | Record 2 | | | | Field 1 | Field 2| ... | | | +------------------------+ | | +------------------------+ | | | Record 3 | | | | Field 1 | Field 2| ... | | | +------------------------+ | +----------------------------+
Data sets will have multiple records, records can have multiple fields, and fields can have multiple values.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrUnsupportedFormat indicates that the file format is not supported. ErrUnsupportedFormat = errors.New("databio/formats: unsupported format") // ErrWriterNotSupported is returned when Writer is not implemented for a Format. ErrWriterNotSupported = errors.New("databio/formats: Writer not supported for this format") )
Functions ¶
Types ¶
type CSV ¶
type CSV struct {
// contains filtered or unexported fields
}
CSV supports reading tabular records from an csv file.
type Format ¶
type Format struct { // Name of the Format used for locating the Reader/Writer to use. Name string // Description of the Format used for selection lists. Description string // Extensions lists the file extensions that typicall denote this Format. // Note each extension MUST begin with a "." dot prefix. Extensions []string // MediaTypes lists the IANA Media/MIME types supported by the Format. MediaTypes []string // Detect if the given (possibly incomplete) data is supported. // Supported = true if this Format will work for the data. // More = true if more data may help detection. // Note that if Supported=false, More=true and you have provided // the entire contents then the data format is either truncated // or not supported. Detect func(data []byte, incomplete bool) (supported bool, more bool) // NewReader returns a new format Reader for the given stream. NewReader func(r io.Reader) (Reader, error) // NewWriter returns a new format Writer applied to the given stream. NewWriter func(w io.Writer) (Writer, error) }
Format describes a supported data interchange protocol.
type Reader ¶
type Reader interface { // Next returns the next Record in the document. Next() (Record, error) // Err returns the last error that occured. Err() error }
Reader returns Records from a supported Format.
type Record ¶
type Record interface { // Each iterates over every field/value pair in the Record. Each(func(field, value string) error) error // Fields returns the a list of Fields present in this Record. Fields() []string // Values returns the values associated with a named Field. Values(field string) []string // Set the values for a named Field in the Record. Set(field string, values []string) }
Record represents a single record sourced from the Format.
type TSV ¶
type TSV struct {
// contains filtered or unexported fields
}
TSV supports reading tabular records from a TSV file.
type Writer ¶
type Writer interface { // Write serializes the Record. Write(Record) error // Err returns the last error that occured. Err() error }
Writer serializes records to a supported Format.
type XLSX ¶
type XLSX struct {
// contains filtered or unexported fields
}
XLSX supports reading tabular records from an excel file.
Click to show internal directories.
Click to hide internal directories.