gncsv

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToRow added in v0.5.1

func ToRow(fields []string) string

ToRow converts a slice of strings representing a CSV row into a single string with comma separation.

Types

type GnCSV

type GnCSV interface {
	Reader
	Writer
}

GnCSV combines Reader and Writer interfaces, providing a unified interface for reading and writing CSV data.

func New

func New(cfg config.Config) GnCSV

New creates a new CSV or TSV/PSV reader/writer based on the provided configuration. If the ColSep in the config is a comma, it creates a CSV reader/writer. Otherwise, it creates a TSV reader/writer.

func NewCSV

func NewCSV(cfg config.Config) GnCSV

NewCSV creates a new GnCSV instance.

func NewTSV

func NewTSV(cfg config.Config) GnCSV

NewTSV creates a new GnCSV instance.

type Reader

type Reader interface {
	// ReadSlice reads a portion of the CSV data, starting at the given
	// offset and reading up to the specified limit. It returns a slice
	// of string slices, where each inner slice represents a row in the CSV.
	ReadSlice(offset, limit int) ([][]string, error)

	// Read reads all CSV data and sends each row as a string slice to
	// the provided channel. It returns the total number of rows read and
	// any error encountered. It uses a context for cancellation.
	Read(context.Context, chan<- []string) (int, error)
}

Reader defines an interface for reading CSV data.

type Writer

type Writer interface {
	// WriteStream writes CSV data received from the provided channel. Each
	// string slice received from the channel represents a row in the CSV.
	// It uses a context for cancellation.
	WriteStream(context.Context, <-chan []string) error
}

Writer defines an interface for writing CSV data.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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