Documentation
¶
Index ¶
- Variables
- func AddFileType(file, filetype string) string
- func CleanUpDirs(dirs []string) []string
- func ConstructFilePath(path, filename, filetype string) (filePath string)
- func DirExists(path string) (exists bool, info os.FileInfo)
- func FileExists(path string) (exists bool, info os.FileInfo)
- func FilesEqual(a, b File) bool
- func HasSuffix(file, suffix string) bool
- func JoinDirs(dirs ...string) (dirPath string)
- func MakeDirectory(path string) error
- func PathIsDir(path string) bool
- func ReadDirectory(dirPath string) (entries []fs.DirEntry)
- func RemoveAllWithinDirectory(path string)
- func SetDebug(newDB bool)
- func SplitDirectories(filePath string) (dirs []string, filename string)
- func SplitFileName(filename string) (name, filetype string)
- func SplitFilePath(filePath string) (path, filename string)
- func ValidDirectoryName(dir string) (isValid bool)
- func ValidFileName(filename string) (isValid bool)
- type File
- func (f *File) Append(bytes []byte)
- func (f *File) ClearFile() error
- func (f *File) Contents() []byte
- func (f File) FullName() string
- func (f *File) IsEmpty() bool
- func (f *File) Name() string
- func (f *File) Path() string
- func (f *File) Read(p []byte) (n int, err error)
- func (f *File) ReadContents() ([]byte, error)
- func (f *File) Rename(path, name string)
- func (f *File) String() string
- func (f *File) Write(p []byte) (n int, err error)
- func (f *File) WriteContents() error
- type TextFile
- func (f *TextFile) Append(s string)
- func (t *TextFile) AppendEmptyLine()
- func (t *TextFile) AppendLastLine(s string)
- func (t *TextFile) AppendLines(arr []string)
- func (f *TextFile) AppendNewLine(s string)
- func (f *TextFile) Contents() []string
- func (t *TextFile) ReadContents() ([]string, error)
- func (t *TextFile) ReadLine(lineNum int) (output string, err error)
- func (t *TextFile) SetLine(s string, i int)
- func (t *TextFile) WriteContents()
Constants ¶
This section is empty.
Variables ¶
var ( ErrPathEmpty = errors.New("files: Path empty. ") ErrNoFileOrDirectory = helpers.WrapError("files: %w", syscall.ENOENT) // special error for "no such file or directory" error that happens sometimes )
var (
ErrNotDir = helpers.WrapError("%w%w", errFiles, errNotDirectory)
)
Functions ¶
func AddFileType ¶
Appends the filetype 'filetype' specified to the end of the 'file' string.
func CleanUpDirs ¶
Returns processes a dirs array, such as one returned by files.SplitDirectories. Main consequences:
- removes any "." directories due to redundancy
Should this return an error if relative imports go up more times than exist within the function?
func ConstructFilePath ¶
This will join together the path, filename, and a specified file type.
func DirExists ¶
DirExists checks if the specified path is a directory. If the directory doesn't exist, it returns false, nil.
func FileExists ¶
FileExists checks if the specified path is a file, or not. If the file doesn't exist, it returns false, nil
func MakeDirectory ¶
MakeDirectory creates a chain of directories based on the path. EG If you ask it to make `~/aasddd/text/no`, and none of those directories exists, it would make them repeatedly.
func PathIsDir ¶
Checks if the path specified is that of a directory. Returns false if the path string is an empty string.
func ReadDirectory ¶
ReadDirectory returns the contents of the specified path as an array of Directory Entries.
func RemoveAllWithinDirectory ¶
func RemoveAllWithinDirectory(path string)
RemoveAllWithinDirectory removes all the files in the specified directory.
func SplitDirectories ¶
This will split up a file path into it's constituting directories, and filename.
func SplitFileName ¶
Name is the whole name up to the very very last .xxx at the end of a filename. EG asd.jar.JAR.jar.txt will consider the filename as asd.jar.JAR.jar and the type as txt
func SplitFilePath ¶
This will isolate a directory path, a file name, and the file type from a specified file path. Rule: Directories end with `/` Rule: Files don't end with a `/` When processing directory or not, if the last one has a dot in it,
func ValidDirectoryName ¶
func ValidFileName ¶
Checks if the filename specified is valid. Should it check if the path is a valid posix name or only the filename is a valid posix name ?
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
The File struct is supposed to handle the io.ReadWriter interface. It treats files as binary objects, writing to them with bytes.
There are two ways to iteract with this file system
- Calling file.Write(byteArr) will write directly the contents of the byte array into the file.
- Calling Append will buffer information into the content buffer, allowing the struct to act as a BufferedWriter in Java Note: When appending to the buffer, at the end you have to
Promises of the File struct - it will fulfill the io.ReadWriteCloser interface
func EmptyFile ¶
func EmptyFile() *File
Returns a basic, empty file for use in comparisons when a method has to return a file but has an inssue. Equivalent of `nil`. Promises of an Empty File: * empty name * empty content buffer * unable to read * unable to write
func NewFile ¶
Creates a new file at a specified directory. Promises of a 'NewFile': * will be created regardless * the new file will have empty contents, inte
func OpenFile ¶
Loads file from memory, loading any contents into the file created. The intended way to create files if they exist within memory.
func (*File) ClearFile ¶
Resets the actual file's contents. Helpful if writing to a pre-existing file and you don't care about the original content.
func (*File) Read ¶
Fulfills io.Reader interface. Reads the file, and returns the number of bytes read.
func (*File) ReadContents ¶
Read the contents of the file into the file buffer. Allows a user to create a file using `NewFile` and then later load the contents into the buffer as desired. Returns: - os.ErrNotExist if the file object does not exist in the file system.
func (*File) String ¶
Returns Important information about the file to be able to gather more information when printing.
func (*File) WriteContents ¶
WriteContents writes the content buffer to the file in the file system.
type TextFile ¶
type TextFile struct {
File // May consider making this an attribute, rather than embed it like this
// contains filtered or unexported fields
}
Contract:
- you can use me to write to files.
func NewTextFile ¶
func (*TextFile) AppendEmptyLine ¶
func (t *TextFile) AppendEmptyLine()
func (*TextFile) AppendLastLine ¶
This adds the specified line at the end of the text. If
func (*TextFile) AppendLines ¶
func (*TextFile) AppendNewLine ¶
func (*TextFile) ReadContents ¶
func (*TextFile) WriteContents ¶
func (t *TextFile) WriteContents()