csv_helper

package
v0.0.0-...-e8a583a Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	APPEND int = os.O_APPEND
	CREATE int = os.O_CREATE
)

Re-export the package `os`'s constants so that packages that depend on csv_helper's `OpenFile` func don't need to depend on package `os` as well

Variables

This section is empty.

Functions

func CSVFilesFromEmbeddedFS

func CSVFilesFromEmbeddedFS(embeddedFS embed.FS, directory string) (csvFilesInDirectory []string)

CSVFilesFromEmbeddedFS returns all csv files in a directory from an embedded FS

func CSVOutputFileName

func CSVOutputFileName(directory, inputFile string) string

CSVOutputFileName returns name of csv file suffixed with the current unix timestamp and with the directory `directory` prefixed to its path Example: inputFile: "./data/something.csv" output: "./data/`directory`/something_`current unix timestamp`.csv"

func FileNameWithUNIXTimestamp

func FileNameWithUNIXTimestamp(file string) string

returns the file name concatenated with the current unix timestamp before the file extension Example: file: "something.csv" output: "something_`current unix timestamp`.csv"

func OpenFile

func OpenFile(file string, osFlag int) (*os.File, error)

OpenFile creates the file `file` and all the directories specified in `file`'s path if they don't exist. The available options for `osFlag` are `APPEND` (which will open the specified file without overwriting it) and `CREATE` (which will overwrite the specified file if it exists)

func ReadCSV

func ReadCSV(fs embed.FS, csvFile string, csvRowsChannel chan []string,
	wg *sync.WaitGroup, nbSkipHeader int)

ReadCSV reads a csv file into the channel `csvRowsChannel`.

func ReadHeader

func ReadHeader(fs embed.FS, csvFile string, nbHeaderRows int) (header [][]string)

ReadHeader returns the specified number of rows from the start of a csv file

func WriteToCSV

func WriteToCSV(outputFile string, osFlags int, csvOutputChannel chan []string, wg *sync.WaitGroup)

WriteToCSV writes to the specified output file with the contents from the channel `csvOutputChannel`. Writing is stopped when `csvOutputChannel` is closed. Please read the doc of `OpenFile` to understand the available options for the `osFlags` argument.

Types

This section is empty.

Jump to

Keyboard shortcuts

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