Documentation
¶
Index ¶
- Constants
- Variables
- func CheckAndMakeDir(dpath string) error
- func FileCompare(fpath1, fpath2 string) (bool, error)
- func FileCompareToString(fpath, str string, trim bool) (bool, error)
- func FileContent(fpath string, trim bool) (string, error)
- func ListFilenames(dirpath string) ([]string, error)
- func ListFilenamesWithFilter(dirpath string, filter FilesFilterFunc) ([]string, error)
- func PathExists(path string) (bool, error)
- type CSVDataSet
- type FileType
- type FileWriter
- type FilesFilterFunc
Constants ¶
const MAX_BYTES_TO_READ = 2 * 1024 // 2KB buffer to read file
const TrimCutSet = " \n\r"
Variables ¶
var ( // FilesCSVFilter is a filter function for csv extension files FilesCSVFilter = GetExtensionFilter("csv") // FilesJSONFilter is a filter function for json extension files FilesJSONFilter = GetExtensionFilter("json") )
Common filters
Functions ¶
func CheckAndMakeDir ¶
CheckAndMakeDir check if the directory exists and creates it with all its tree structure if not.
func FileCompare ¶
FileCompare return true if the files have the same content (byte to byte), false otherwize with an error indicating the differences
func FileContent ¶
FileContent returns the content of the file as a string (the content is supposed to be a readable text). If trim is true then the string is trimmed by left and right from unexpected characters space, \n and \r.
func ListFilenames ¶
ListFilenames returns the names of files in dirpath (no filter)
func ListFilenamesWithFilter ¶
func ListFilenamesWithFilter(dirpath string, filter FilesFilterFunc) ([]string, error)
ListFilenamesWithFilter returns the names of files in dirpath that satisfy the filter
func PathExists ¶
PathExists returns true if the path exists, and false otherwize. In the case where the file is considered as not existing, the err can help you to check the actual reason (maybe it exists but can not be reached). Even if the file exists, there could have an error, then check bool AND error results.
Types ¶
type CSVDataSet ¶
func CSVload ¶
func CSVload(csvpath string) (CSVDataSet, error)
CSVload loads the data from this CSV file. The data are return as a list of maps corresponding for each row to a map whose keys are the column names and values the column values.
type FileType ¶
type FileType string
func GetFileType ¶
GetFileType returns the content type of the file, as the shell command file would return. The type is determined by analysing the header content of the file.
type FileWriter ¶
FileWriter returns a buffer writer to a given file
func NewFileWriter ¶
func NewFileWriter(fpath string) (*FileWriter, error)
NewFileWriter is an execution of NewFileWriterWithFlag with the default flag
func NewFileWriterWithFlag ¶
func NewFileWriterWithFlag(fpath string, flag int) (*FileWriter, error)
NewFileWriterWithFlag open a writer to the output file specified by path. If the directory containing this path does not exist, then it tries to create it.
func (FileWriter) Close ¶
func (w FileWriter) Close() error
type FilesFilterFunc ¶
FilesFilterFunc represents a function used to filter files by name
func GetExtensionFilter ¶
func GetExtensionFilter(ext string) FilesFilterFunc
GetExtensionFilter returns a FilesFilterFunc that can be used to filter files with the specified extension