Documentation ¶
Overview ¶
Package fileio provides wrappers of the builtin golang Reader/Writer utilities for ease of use and automatic gzip handling.
Index ¶
- func AreEqual(a string, b string) bool
- func AreEqualIgnoreComments(a string, b string) bool
- func AreEqualIgnoreOrder(a string, b string) bool
- func CatUrl(url string) string
- func CatchErrThrowEOF(err error)
- func EasyNextLine(file *EasyReader) (string, bool)
- func EasyNextRealLine(file *EasyReader) (string, bool)
- func EasyPeekReal(file *EasyReader, n int) ([]byte, error)
- func EasyReadHeader(file *EasyReader) ([]string, error)
- func EasyRemove(filename string)
- func IntSliceToString(nums []int) string
- func IntToString(i int) string
- func IsGzip(r io.ReadSeeker) bool
- func MustCreate(filename string) *os.File
- func MustOpen(filename string) *os.File
- func MustRemove(filename string)
- func NextLine(reader *bufio.Reader) (string, bool)
- func NextRealLine(reader *bufio.Reader) (string, bool)
- func PeekReal(reader *bufio.Reader, n int) ([]byte, error)
- func Read(filename string) []string
- func ReadFileToSingleLineString(filename string) string
- func ReadHeader(reader *bufio.Reader) ([]string, error)
- func ReadLine(reader *ByteReader) (*bytes.Buffer, bool)
- func StringToIntSlice(line string) []int
- func Write(filename string, records []string)
- func WriteToFileHandle(file io.Writer, rec string)
- type ByteReader
- type EasyReader
- type EasyWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AreEqual ¶
AreEqual returns true if input files are equal. Expects files to end with a newline character.
func AreEqualIgnoreComments ¶
AreEqualIgnoreComments returns true if input files are equal. This function ignores lines beginning with #.
func AreEqualIgnoreOrder ¶
AreEqualIgnoreOrder returns true if input files contain the same lines, although the order of the lines does not matter. This program sorts the two files and compares the contents, so it is not well suited for large files as the whole contents are read into memory.
func CatchErrThrowEOF ¶
func CatchErrThrowEOF(err error)
CatchErrThrowEOF handles EOF errors silently and panics on others.
func EasyNextLine ¶
func EasyNextLine(file *EasyReader) (string, bool)
EasyNextLine returns the next line of the input EasyReader. Returns true at EOF.
func EasyNextRealLine ¶
func EasyNextRealLine(file *EasyReader) (string, bool)
EasyNextRealLine returns the next line of the input EasyReader that does not begin with '#'. Returns true at EOF.
func EasyPeekReal ¶
func EasyPeekReal(file *EasyReader, n int) ([]byte, error)
EasyPeekReal will advance a reader past any lines beginning with '#' and read the first n bytes without advancing the reader.
func EasyReadHeader ¶
func EasyReadHeader(file *EasyReader) ([]string, error)
EasyReadHeader will read any leading comments lines from the file and return them as a slice of strings with each element in the slice being a comment line.
func IntSliceToString ¶
IntSliceToString converts int slices to comma-separated strings.
func IsGzip ¶
func IsGzip(r io.ReadSeeker) bool
IsGzip checks if the magic gzip number is present at the start of the input io.ReadSeeker. After check for the magic number, IsGzip seeks back to the initial position.
func MustCreate ¶
MustCreate creates a file with the input name. Fatal/Panics when appropriate.
func MustRemove ¶
func MustRemove(filename string)
MustRemove deletes the input file. Fatal/Panics when appropriate.
func NextLine ¶
NextLine returns the next line of the file (might be a comment line). Returns true if the file is done.
func NextRealLine ¶
NextRealLine returns the next line of the file that is not a comment line. Returns true if the file is done.
func PeekReal ¶
PeekReal will advance a reader past any lines beginning with '#' and read the first n bytes without advancing the reader.
func ReadFileToSingleLineString ¶
ReadFileToSingleLineString reads in any file type and returns contents without any \n.
func ReadHeader ¶
ReadHeader will advance a reader past initial lines that begin with '#', returning a slice of these comments lines and leaving the reader at the first non-comment line.
func ReadLine ¶
func ReadLine(reader *ByteReader) (*bytes.Buffer, bool)
ReadLine reads a line into Buffer, indicating if more lines are available.
func StringToIntSlice ¶
StringToIntSlice converts comma-separated strings to int slices.
func Write ¶
Write writes a slice of strings to a file with a newline placed after each element of the slice.
func WriteToFileHandle ¶
WriteToFileHandle will write a string to an io.Writer and panic on any error.
Types ¶
type ByteReader ¶
type ByteReader struct { *bufio.Reader File *os.File Buffer *bytes.Buffer // contains filtered or unexported fields }
ByteReader wraps bufio.Reader for efficient byte-level file parsing.
func NewByteReader ¶
func NewByteReader(filename string) *ByteReader
NewByteReader initializes a ByteReader for given filename, supporting p/gzip.
func (*ByteReader) Close ¶
func (br *ByteReader) Close() error
Close closes the internal File and gzip Reader if present.
type EasyReader ¶
type EasyReader struct { File *os.File BuffReader *bufio.Reader // contains filtered or unexported fields }
EasyReader provides a simplified wrapper of the builtin golang io functions. Will silently handle reading gziped files. EasyReader is a valid io.Reader.
func EasyHttp ¶
func EasyHttp(url string) *EasyReader
EasyHttp will fetch data from files uploaded to an internet server and stream data into EasyReader.
func EasyOpen ¶
func EasyOpen(filename string) *EasyReader
EasyOpen opens the input file. Panics if errors are encountered.
type EasyWriter ¶
type EasyWriter struct {
// contains filtered or unexported fields
}
EasyWriter provides a simplified wrapper of the builtin golang io functions. Will silently gzip output files when the input filename ends with '.gz'. EasyWriter is a valid io.Writer.
func EasyCreate ¶
func EasyCreate(filename string) *EasyWriter
EasyCreate creates a file with the input name. Panics if errors are encountered.