csv

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 LibreOffice prints a CSV file that it opens, 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. The text is in Liberation Sans of 10 points. A field that holds a number is aligned to the right, and the other fields to the left. Each column is as wide as LibreOffice makes it, from its first field with the most characters, up to the width of the page, and a longer field breaks into lines. A row is as high as LibreOffice prints a row of the default height, 12.784 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

View Source
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

func Open(ctx context.Context, src ivy.Source, opts ...Option) (d *Document, err error)

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.

func (*Document) Close

func (d *Document) Close() error

Close satisfies the ivy.Document interface.

func (*Document) Page

func (d *Document) Page(ctx context.Context, n int) (ivy.Page, error)

Page satisfies the ivy.Pager interface. It lays out the table only as far as page n.

func (*Document) PageCount

func (d *Document) PageCount(ctx context.Context) (int, error)

PageCount satisfies the ivy.Pager interface. It lays out the whole table on its first call.

type Option

type Option func(*options)

Option is an option of Open.

func WithConfig

func WithConfig(cfg ivy.Config) Option

WithConfig sets the configuration that every format shares.

func WithSeparator

func WithSeparator(r rune) Option

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.

Jump to

Keyboard shortcuts

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