tsv

package
v0.0.0-...-b9741f9 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2023 License: BSD-2-Clause Imports: 5 Imported by: 2

Documentation

Overview

Package tsv implements a tsv reader.

This custom package is used as replacement of the standard library csv package as GBIF tab delimited files are not compatible with the quotation rules used by that package.

Index

Constants

This section is empty.

Variables

View Source
var ErrFieldCount = errors.New("wrong number of fields")

Parsing errors.

Functions

This section is empty.

Types

type Reader

type Reader struct {
	// Ignored field,
	// used for compatibility
	// with standard library csv package.
	Comma rune
	// contains filtered or unexported fields
}

A Reader reads records from a TSV-encoded file.

The Reader converts all \r\n sequences in its input to plain \n.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader returns a new Reader that reads from r.

func (*Reader) FieldPos

func (r *Reader) FieldPos(field int) (line, column int)

FieldPos returns the line corresponding to the record most recently read by Read.

Defined for compatibility with standard library csv package. The field location is ignored, and the column is always 0.

func (*Reader) Read

func (r *Reader) Read() (record []string, err error)

Read reads one record from r. If the record has an unexpected number of fields, Read returns the record along with the error ErrFieldCount. If there is no data left to be read, Read returns nil, io.EOF

type Writer

type Writer struct {
	// Unused,
	// for compatibility with standard library csv package
	Comma   rune
	UseCRLF bool
	// contains filtered or unexported fields
}

A Writer writes records using TSV encoding.

Tab is the field delimiter. The Writer ends each output line with \r\n.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter returns a new Writer that writes to w.

func (*Writer) Error

func (w *Writer) Error() error

Error reports any error that has occurred during a previous Write or Flush.

func (*Writer) Flush

func (w *Writer) Flush()

Flush writes any buffered data to the underlying io.Writer. To check if an error occurred during the Flush, call Error.

func (*Writer) Write

func (w *Writer) Write(record []string) error

Write writes a single TSV record to w along with any necessary escaping. 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.

Jump to

Keyboard shortcuts

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