file

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package file provides util primitives to file operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoRename added in v1.2.0

func AutoRename(filePath string) error

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

func CleanseFolderFileName(name string) string

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

func DecodeStructFromFile(fileName string, data interface{}) error

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

func EncodeStructToFile(fileName string, data interface{}) error

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

func EnsureDir added in v1.1.4

func EnsureDir(dir string) error

EnsureDir is a helper function that ensures that the directory exists by creating them if they do not already exist.

func Exists

func Exists(name string) bool

Exists checks if the given file exists.

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.

Jump to

Keyboard shortcuts

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