Documentation ¶
Overview ¶
Package csvutil is not maintained. It provides formatted reading and writing of CSV data.
Index ¶
- Variables
- func Do(r io.Reader, f func(r Row) bool)
- func DoFile(filename string, f func(r Row) bool) error
- func Read(r io.Reader) ([][]string, error)
- func ReadFile(filename string) ([][]string, error)
- func Write(w io.Writer, rows [][]string) (int, error)
- func WriteFile(filename string, perm os.FileMode, rows [][]string) (int, error)
- type Config
- type Reader
- func (csvr *Reader) Do(f func(Row) bool)
- func (csvr *Reader) DoN(n int, f func(Row) bool)
- func (csvr *Reader) LineNum() int
- func (csvr *Reader) ReadRow() Row
- func (csvr *Reader) ReadRows(rbuf [][]string) (int, error)
- func (csvr *Reader) RemainingRows() (rows [][]string, err error)
- func (csvr *Reader) RemainingRowsSize(size int) ([][]string, error)
- type Row
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ( FloatFmt byte = 'g' FloatPrec int = -1 )
See strconv.Ftoa32()
var ( ErrorIndex = errors.New("Not enough fields to format") ErrorStruct = errors.New("Cannot format unreferenced structs") ErrorUnimplemented = errors.New("Unimplemented field type") ErrorFieldType = errors.New("Field type incompatible.") ErrorNonPointer = errors.New("Target is not a pointer.") ErrorCantSet = errors.New("Cannot set value.") )
var ( DefaultConfig = &Config{ Sep: ',', Trim: false, Cutset: " \t", CommentPrefix: "#", Comments: false, CommentsInBody: false} )
The default configuration is used for Readers and Writers when none is given.
Functions ¶
Types ¶
type Config ¶
type Config struct { // General configuration // Field seperator Sep rune // Trim leading/trailing whitespace in fields. Trim bool // Characters to trim from fields. Cutset string // Prefix for comment lines. CommentPrefix string // Reader specific config // Are comments allowed in the input. Comments bool // Comments can appear in the body (Comments must be true). CommentsInBody bool }
A configuration structure that can be shared between a Reader and Writer.
func NewConfig ¶
func NewConfig() *Config
Return a freshly allocated Config that is initialized to DefaultConfig.
func (*Config) LooksLikeComment ¶
type Reader ¶
type Reader struct { *Config // contains filtered or unexported fields }
A reader object for CSV data utilizing the bufio package.
func NewReaderSize ¶
Create a new reader with a buffer of a specified size.
func (*Reader) Do ¶
Iteratively read the remaining rows in the reader and call f on each of them. If f returns false, no more rows will be read.
func (*Reader) DoN ¶
Process rows from the reader like Do, but stop after processing n of them. If f returns false before n rows have been process, no more rows will be processed.
func (*Reader) ReadRow ¶
Attempt to read up to a new line, skipping any comment lines found in the process. Return a Row object containing the fields read and any error encountered.
func (*Reader) ReadRows ¶
Read rows into a preallocated buffer. Return the number of rows read, and any error encountered.
func (*Reader) RemainingRows ¶
Reads any remaining rows of CSV data in the underlying io.Reader.
type Row ¶
A simple row structure for rows read by a csvutil.Reader that encapsulates any read error enountered along with any data read prior to encountering an error.
func FormatRow ¶
func FormatRow(x ...interface{}) Row
Iteratively take values from the argument list and formats them (or their elements/fields) as a (list of) string(s). Returns a Row object that contains the formatted arguments, as well as any error that occured.
type Writer ¶
type Writer struct { *Config // contains filtered or unexported fields }
A simple CSV file writer using the package bufio for effeciency. But, because of this, the method Flush() must be called to ensure data is written to any given io.Writer before it is closed.
func NewWriter ¶
Create a new CSV writer with the default field seperator and a buffer of a default size.
func NewWriterSize ¶
Create a new CSV writer using a buffer of at least n bytes.
See bufio.NewWriterSize(io.Writer, int) (*bufio.NewWriter).
func (*Writer) WriteComments ¶
Write a comment. Each comment string given will start on a new line. If the string is contains multiple lines, comment prefixes will be inserted at the beginning of each one.
func (*Writer) WriteFields ¶
Write a slice of field values with a trailing field seperator (no '\n'). Returns any error incurred from writing.