Namespace: go.std.encoding.csv
v1.0Contents
Summary
Provides a low-level interface to the encoding/csv package.
Package csv reads and writes comma-separated values (CSV) files.
There are many kinds of CSV files; this package supports the format
described in RFC 4180.
A csv file contains zero or more records of one or more fields per record.
Each record is separated by the newline character. The final record may
optionally be followed by a newline character.
field1,field2,field3
White space is considered part of a field.
Carriage returns before newline characters are silently removed.
Blank lines are ignored. A line with only whitespace characters (excluding
the ending newline character) is not considered a blank line.
Fields which start and stop with the quote character " are called
quoted-fields. The beginning and ending quote are not part of the
field.
The source:
normal string,"quoted-field"
results in the fields
{`normal string`, `quoted-field`}
Within a quoted-field a quote character followed by a second quote
character is considered a single quote.
"the ""word"" is true","a ""quoted-field"""
results in
{`the "word" is true`, `a "quoted-field"`}
Newlines and commas may be included in a quoted-field
"Multi-line
field","comma is ,"
results in
{`Multi-line
field`, `comma is ,`}
Index
- *ParseError
- *Reader
- *Writer
- ErrBareQuote
- ErrFieldCount
- ErrQuote
- ErrTrailingComma
- NewReader
- NewWriter
- ParseError
- Reader
- Writer
- arrayOfParseError
- arrayOfReader
- arrayOfWriter
Legend
-
Constant
Variable
Function
Macro
Special form
Type
GoVar
Receiver/Method
Constants
Constants are variables with :const true in their metadata. Joker currently does not recognize them as special; as such, it allows redefining them or their values.-
(None.)
Variables
-
ErrBareQuote
Var v1.0These are the errors that can be returned in ParseError.Err.
-
ErrFieldCount
Var v1.0These are the errors that can be returned in ParseError.Err.
-
ErrQuote
Var v1.0These are the errors that can be returned in ParseError.Err.
-
ErrTrailingComma
Var v1.0Deprecated: No longer used.
Functions, Macros, and Special Forms
-
NewReader
Function v1.0(NewReader r)
NewReader returns a new Reader that reads from r.
Go input arguments: (r io.Reader)
Go returns: *Reader
Joker input arguments: [^go.std.io/Reader r]
Joker returns: ^*Reader -
NewWriter
Function v1.0(NewWriter w)
NewWriter returns a new Writer that writes to w.
Go input arguments: (w io.Writer)
Go returns: *Writer
Joker input arguments: [^go.std.io/Writer w]
Joker returns: ^*Writer
Types
-
*ParseError
Concrete Type v1.0A ParseError is returned for parsing errors.
Line numbers are 1-indexed and columns are 0-indexed.
-
Error
Receiver for *ParseError v1.0([])
-
Unwrap
Receiver for *ParseError v1.0([])
-
*Reader
Concrete Type v1.0A Reader reads records from a CSV-encoded file.
As returned by NewReader, a Reader expects input conforming to RFC 4180.
The exported fields can be changed to customize the details before the
first call to Read or ReadAll.
The Reader converts all \r\n sequences in its input to plain \n,
including in multiline field values, so that the returned data does
not depend on which line-ending convention an input file uses.
-
FieldPos
Receiver for *Reader v1.0([field])
FieldPos returns the line and column corresponding to
the start of the field with the given index in the slice most recently
returned by Read. Numbering of lines and columns starts at 1;
columns are counted in bytes, not runes.
If this is called with an out-of-bounds index, it panics.
-
InputOffset
Receiver for *Reader v1.0([])
InputOffset returns the input stream byte offset of the current reader
position. The offset gives the location of the end of the most recently
read row and the beginning of the next row.
-
Read
Receiver for *Reader v1.0([])
Read reads one record (a slice of fields) from r.
If the record has an unexpected number of fields,
Read returns the record along with the error ErrFieldCount.
Except for that case, Read always returns either a non-nil
record or a non-nil error, but not both.
If there is no data left to be read, Read returns nil, io.EOF.
If ReuseRecord is true, the returned slice may be shared
between multiple calls to Read.
-
ReadAll
Receiver for *Reader v1.0([])
ReadAll reads all the remaining records from r.
Each record is a slice of fields.
A successful call returns err == nil, not err == io.EOF. Because ReadAll is
defined to read until EOF, it does not treat end of file as an error to be
reported.
-
*Writer
Concrete Type v1.0A Writer writes records using CSV encoding.
As returned by NewWriter, a Writer writes records terminated by a
newline and uses ',' as the field delimiter. The exported fields can be
changed to customize the details before the first call to Write or WriteAll.
Comma is the field delimiter.
If UseCRLF is true, the Writer ends each output line with \r\n instead of \n.
The writes of individual records are buffered.
After all data has been written, the client should call the
Flush method to guarantee all data has been forwarded to
the underlying io.Writer. Any errors that occurred should
be checked by calling the Error method.
-
Error
Receiver for *Writer v1.0([])
Error reports any error that has occurred during a previous Write or Flush.
-
Flush
Receiver for *Writer v1.0([])
Flush writes any buffered data to the underlying io.Writer.
To check if an error occurred during the Flush, call Error.
-
Write
Receiver for *Writer v1.0([record])
Write writes a single CSV record to w along with any necessary quoting.
A record is a slice of strings with each string being one field.
Writes are buffered, so Flush must eventually be called to ensure
that the record is written to the underlying io.Writer.
-
WriteAll
Receiver for *Writer v1.0([records])
WriteAll writes multiple CSV records to w using Write and then calls Flush,
returning any error from the Flush.
-
ParseError
Concrete Type v1.0A ParseError is returned for parsing errors.
Line numbers are 1-indexed and columns are 0-indexed.
-
Reader
Concrete Type v1.0A Reader reads records from a CSV-encoded file.
As returned by NewReader, a Reader expects input conforming to RFC 4180.
The exported fields can be changed to customize the details before the
first call to Read or ReadAll.
The Reader converts all \r\n sequences in its input to plain \n,
including in multiline field values, so that the returned data does
not depend on which line-ending convention an input file uses.
-
Writer
Concrete Type v1.0A Writer writes records using CSV encoding.
As returned by NewWriter, a Writer writes records terminated by a
newline and uses ',' as the field delimiter. The exported fields can be
changed to customize the details before the first call to Write or WriteAll.
Comma is the field delimiter.
If UseCRLF is true, the Writer ends each output line with \r\n instead of \n.
The writes of individual records are buffered.
After all data has been written, the client should call the
Flush method to guarantee all data has been forwarded to
the underlying io.Writer. Any errors that occurred should
be checked by calling the Error method.
-
arrayOfParseError
Concrete Type v1.0A ParseError is returned for parsing errors.
Line numbers are 1-indexed and columns are 0-indexed.
-
arrayOfReader
Concrete Type v1.0A Reader reads records from a CSV-encoded file.
As returned by NewReader, a Reader expects input conforming to RFC 4180.
The exported fields can be changed to customize the details before the
first call to Read or ReadAll.
The Reader converts all \r\n sequences in its input to plain \n,
including in multiline field values, so that the returned data does
not depend on which line-ending convention an input file uses.
-
arrayOfWriter
Concrete Type v1.0A Writer writes records using CSV encoding.
As returned by NewWriter, a Writer writes records terminated by a
newline and uses ',' as the field delimiter. The exported fields can be
changed to customize the details before the first call to Write or WriteAll.
Comma is the field delimiter.
If UseCRLF is true, the Writer ends each output line with \r\n instead of \n.
The writes of individual records are buffered.
After all data has been written, the client should call the
Flush method to guarantee all data has been forwarded to
the underlying io.Writer. Any errors that occurred should
be checked by calling the Error method.