iotools

package
v0.0.0-...-04a4f9f Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2022 License: GPL-3.0 Imports: 8 Imported by: 43

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DELIM = []string{"\t", ",", "|", ";", ":", " "}

Functions

func AppendFile

func AppendFile(file string) *os.File

AppendFile opens the file at the given file path and returns file stream in append mode. It will exit if it encounters an error.

func CheckError

func CheckError(msg string, err error, code int) bool

CheckError returns true if err is nil; otherwise, if code is 0 it prints a warning and returns false. If code is not 0, it prints an error formatted with msg and exits with code.

func CreateFile

func CreateFile(file string) *os.File

CreateFile creates a file at the given file path and returns a file stream. It will exit if it encounters an error.

func Exists

func Exists(path string) bool

Exists seturns true if the given file or directory exists.

func FindDelim

func FindDelim(infile string) (string, error)

FindDelim returns delimiter (tab, comma, pipe, semicolon, colon, or space) from a text file. Returns an error if delimiter cannot be found.

func FormatPath

func FormatPath(path string, makenew bool) (string, bool)

FormatPath returns path name with trailing slash (os.PathSeparator) and makes the directory if makenew is true.

func GetDelim

func GetDelim(header string) (string, error)

GetDelim returns delimiter (tab, comma, pipe, semicolon, colon, or space) from a line of a text file. Returns an error if delimiter cannot be found.

func GetExt

func GetExt(file string) string

GetExt returns the file extension (everthing after the last period) from file.

func GetFileName

func GetFileName(file string) string

GetFileName returns the base name (everything between the final slash and first period) from file.

func GetGOPATH

func GetGOPATH() string

GetGOPATH returns gopath environent environment variable.

func GetHeader

func GetHeader(row []string) map[string]int

GetHeader returns a map of header names to indeces.

func GetParent

func GetParent(path string) string

GetParent returns name of parent directory from path.

func GetScanner

func GetScanner(f *os.File) *bufio.Scanner

GetScanner determines if a file is gzipped or not returns the appropriate scanner. It will exit if it encounters an error.

func Gzip

func Gzip(outfile, header string, results [][]string)

Gzip compresses infile to same directory. Adds '.gz' extension.

func OpenFile

func OpenFile(file string) *os.File

OpenFile opens the file at the given file path and returns a file stream. It will exit if it encounters an error.

func ReadFile

func ReadFile(infile string, header bool) ([][]string, map[string]int)

ReadFile reads in compressed and uncompressed text files as a two dimensional slice of strings and the header as a map of indeces.

func WriteToCSV

func WriteToCSV(outfile, header string, results [][]string)

WriteToCSV writes a string header and a two dimensional slice of strings to csv. Gzips file if last three characters of file name are '.gz'.

func YieldFile

func YieldFile(infile string, header bool) (<-chan []string, map[string]int)

YieldFile reads compressed and uncompressed text files and returns the header as a map of indeces and the lines as an iterable channel of string slices.

		reader, header := iotools.YieldFile(infile, true)
     for i := range reader { ...

Types

This section is empty.

Jump to

Keyboard shortcuts

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