Documentation ¶
Overview ¶
Package file provides util primitives to file operations.
Index ¶
- func AutoRename(filePath string) error
- func CleanseFolderFileName(name string) string
- func DecodeStructFromFile(fileName string, data interface{}) error
- func EncodeStructToFile(fileName string, data interface{}) error
- func EnsureDir(dir string) error
- func Exists(name string) bool
- type FileNotFoundError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoRename ¶ added in v1.2.0
AutoRename renames a file by prepending "[EditX]" to its fileName where X is a positive integer. X increments itself starting from 1 until the there exists a the new fileName does not exist in the directory.
func CleanseFolderFileName ¶ added in v1.1.4
CleanseFolderFileName is a helper function that ensures folders' and files' names are valid, that they do not contain prohibited characters. However, some are still not caught for unlikeliness and simplicity reasons. The following are reserved file names for Windows that are uncaught: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9. The following are non-printable characters that are uncaught: ASCII 0-31.
func DecodeStructFromFile ¶
DecodeFromFile decodes any type that has been encoded back into its original type. Works with structs, primitives and objects like time.Time. Provide a pointer of the type to write to. Provide absolute path else file may not be found. TODO CHANGE name to DecodeToFile
func EncodeStructToFile ¶
EncodeToFile takes in any type and encodes it into a file specified by fileName. If the file already exists, it is truncated. If the file does not exist, it is created with mode 0666 (before umask). Provide absolute path else file will be written to the current working directory. TODO CHANGE name to EncodeToFile
Types ¶
type FileNotFoundError ¶
type FileNotFoundError struct {
FileName string
}
FileNotFoundError struct is an error struct that contains the custom error that will be thrown when file is not found.
func (*FileNotFoundError) Error ¶
func (e *FileNotFoundError) Error() string
FileNotFoundError is an error that will be thrown when file is not found.