csvtrans

package module
v0.0.0-...-e181b2d Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2015 License: MIT Imports: 5 Imported by: 0

README

csvtrans

csvtrans is a small utility library for transforming CSV files. The library essentially removes the boilerplate needed to iterate through a CSV, so all that is needed is to specify the source, destination and a function which transforms individual rows.

See here for documentation.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(in io.Reader, out io.Writer, f RowTransformer) error

Run performs the transformation on the CSV given an input reader, output writer and a function to transform each row.

func RunFile

func RunFile(inFile, outFile string, f RowTransformer) error

RunFile is a wrapper around Run. This uses files as the input and output. Different filenames must be passed in to the function. If an output file already exists, it will be replaced.

Types

type BufRowTransformer

type BufRowTransformer func(i int, inRow []string, outRow []string) ([]string, error)

BufRowTransformer is similar to RowTransformer, but also takes a buffer which should be returned. This allows the output CSV to reuse a buffer between calls, to reduce garbage

type RowTransformer

type RowTransformer func(i int, inRow []string) (outRow []string, err error)

RowTransformer is a function that transforms a CSV row. If an error is returned, the CSV transformation will terminate. If a row is to be skipped, return with outRow and err == nil

func MakeRowTransformer

func MakeRowTransformer(length int, f BufRowTransformer) RowTransformer

Creates a RowTransformer from a BufRowTransformer which reuses the same buffer. Note that when using a BufRowTransformer with this that every field must be set each iteration, or values will be repeated between rows. length is the number of columns in the output CSV

Jump to

Keyboard shortcuts

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