Documentation ¶
Overview ¶
Package file handles simple file related tools for ease of use
Index ¶
- Constants
- Variables
- func AppendToAsciiFile(filename, value string) error
- func AsciiFileToLines(filename string) []string
- func AsciiFileToString(fileName string) string
- func CleanFolder(chain, rootFolder string, subFolders []string) error
- func Copy(destPath, sourcePath string) (int64, error)
- func EarliestFileInFolder(path string) (string, error)
- func Empty(file *os.File) (err error)
- func EstablishFolder(rootPath string) error
- func EstablishFolders(rootPath string, folders []string) error
- func FileExists(filename string) bool
- func FileSize(filename string) int64
- func FolderExists(path string) bool
- func GetModTime(fn string) (time.Time, error)
- func GetNewestInDirectory(directory string) (fileInfo os.FileInfo, err error)
- func GetPathParts(fullPath string) (folder string, filename string, ext string)
- func IsFolderEmpty(folder string) (bool, error)
- func IsLaterThan(fn1, fn2 string) (bool, error)
- func IsTestMode() bool
- func IsValidFolderName(folderName string) (bool, error)
- func LatestFileInFolder(path string) (string, error)
- func LinesToAsciiFile(filename string, value []string) error
- func Lock(file *os.File) error
- func MustGetLatestFileTime(folders ...string) time.Time
- func NFilesInFolder(path string) int
- func Remove(fileName string) bool
- func RunWithFileSupport(mode string, run func(cmd *cobra.Command, args []string) error, ...) func(cmd *cobra.Command, args []string) error
- func StringToAsciiFile(filename, value string) error
- func Touch(filename string) bool
- func Unlock(file *os.File) error
- func ValidFilename(in string, noSpaces bool) string
- func WaitOnLock(filePath string, openFlags int) (file *os.File, err error)
- func WordCount(fileName string, ignoreHeader bool) (int, error)
- type BackupFile
- type CommandFileLine
- type CommandsFile
Constants ¶
const ( // MagicNumber is used to check data validity MagicNumber = 0xdeadbeef SmallMagicNumber = uint16(0xdead) )
Variables ¶
var DefaultOpenFlags = os.O_RDWR | os.O_CREATE
Functions ¶
func AppendToAsciiFile ¶
func AsciiFileToLines ¶
func AsciiFileToString ¶
func CleanFolder ¶
CleanFolder removes any files that may be partial or incomplete
func EarliestFileInFolder ¶
EarliestFileInFolder returns the first (alphabetically) file in the folder
func Empty ¶
Empty is a shortcut function to seek to the beginning of a file and truncate it to 0. It does not call file.Sync though, making all operations in-memory only.
func EstablishFolder ¶
EstablishFolder creates folders given a list of folders
func EstablishFolders ¶
EstablishFolders creates the rootPath and any subfolders
func FileExists ¶
func FolderExists ¶
func GetNewestInDirectory ¶
func IsFolderEmpty ¶
func IsLaterThan ¶
func IsTestMode ¶
func IsTestMode() bool
func IsValidFolderName ¶
IsValidFolderName checks if the folder name is valid and does not exist in the current directory.
func LatestFileInFolder ¶
LatestFileInFolder returns the latest (alphabetically) file in the folder
func LinesToAsciiFile ¶
func MustGetLatestFileTime ¶
func NFilesInFolder ¶
func RunWithFileSupport ¶
func RunWithFileSupport( mode string, run func(cmd *cobra.Command, args []string) error, resetOptions func(testMode bool), ) func(cmd *cobra.Command, args []string) error
RunWithFileSupport returns a function to run Cobra command. The command runs in the usual way unless `--file` is specified. If it is specified, this function will parse the file and then run the command in series of independent calls (just like calling `chifra` N times on the command line, but without wasting time and resources for the startup)
func StringToAsciiFile ¶
func ValidFilename ¶
ValidFilename returns a valid filename from the input string
func WaitOnLock ¶
WaitOnLock tries to lock a file for maximum `maxSecondsLock`
Types ¶
type BackupFile ¶
func MakeBackup ¶
func MakeBackup(tmpPath, origFn string) (BackupFile, error)
MakeBackup creates a backup of the original file and returns a structure that can be used to restore the original file in case of an error.
func (*BackupFile) Restore ¶
func (bf *BackupFile) Restore()
Restore restores the original file from the backup file.
type CommandFileLine ¶
CommandFileLine stores line number for future reference, flag (usually a string that starts with "-" or "--") and args (any other string) information
type CommandsFile ¶
type CommandsFile struct {
Lines []CommandFileLine
}
CommandsFile is data structure representing the text file with commands (flags and arguments) on each line. Lines trigger independent invocations of given chifra subcommand.
func ParseCommandsFile ¶
func ParseCommandsFile(cmd *cobra.Command, filePath string) (cf CommandsFile, err error)
ParseCommandsFile parses a text file into `CommandsFile` struct. While parsing, the function validates flags present on the current line.