Documentation
¶
Overview ¶
Package csv opens files of values separated by commas, semicolons, tabs or vertical bars: .csv, .tsv and .tab.
A document puts the rows into one table on pages, as a sheet of Excel prints them, with the package sheet and the layout of D10. The table has light gridlines, because a file of values has no style that separates its cells. A field that holds a number is aligned to the right, and the other fields to the left. Each column is as wide as its longest field in Calibri, from 48 to 300 points, and a longer field breaks into lines. A row is as high as Excel prints a row of 15 points.
The package finds the separator in the first records: the one that gives the same number of fields, more than one, to the most records. WithSeparator gives the separator instead (D36). The package reads the quotes of RFC 4180, and a quote in a field without quotes as text. It reads UTF-8 with or without a byte order mark, UTF-16 with a byte order mark or with the zero bytes of ASCII text, and windows-1252 for any other text that is not valid UTF-8.
Each cell shows its field as the file writes it. The package does not guess dates, because a wrong guess changes the data that a person reviews (D36).
A file reads at most Limits.MaxMemory bytes and Limits.MaxObjects fields. A file with more fields shows the fields up to the limit, and a line after the table says so. A file with a zero byte that is not UTF-16 is not a text file, and Open returns an error that wraps ivy.ErrFormat.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Format = ivy.Format{ Name: "csv", Mimes: []string{"text/csv", "text/tab-separated-values", "application/csv", "text/x-csv"}, Exts: []string{"csv", "tsv", "tab"}, Open: func(ctx context.Context, src ivy.Source, cfg ivy.Config) (ivy.Document, error) { return Open(ctx, src, WithConfig(cfg)) }, }
Format describes the package for the registry of a program.
Functions ¶
This section is empty.
Types ¶
type Document ¶
type Document struct {
// contains filtered or unexported fields
}
Document is an open file of separated values.
func Open ¶
Open reads a file of separated values and its records. It returns an error that wraps ivy.ErrFormat for a file that is not text, and one that wraps ivy.ErrLimit for a file larger than Limits.MaxMemory.
type Option ¶
type Option func(*options)
Option is an option of Open.
func WithConfig ¶
WithConfig sets the configuration that every format shares.
func WithSeparator ¶
WithSeparator sets the separator of the fields, such as ';'. Without it, or with the zero rune, the package finds the separator in the first records. A quote, a line break or a rune that is not valid makes Open return an error that wraps ivy.ErrUnsupported.