files

package
v0.0.0-...-cb2066d Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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
)
View Source
var (
	ErrNotDir = helpers.WrapError("%w%w", errFiles, errNotDirectory)
)

Functions

func AddFileType

func AddFileType(file, filetype string) string

Appends the filetype 'filetype' specified to the end of the 'file' string.

func CleanUpDirs

func CleanUpDirs(dirs []string) []string

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

func ConstructFilePath(path, filename, filetype string) (filePath string)

This will join together the path, filename, and a specified file type.

func DirExists

func DirExists(path string) (exists bool, info os.FileInfo)

DirExists checks if the specified path is a directory. If the directory doesn't exist, it returns false, nil.

func FileExists

func FileExists(path string) (exists bool, info os.FileInfo)

FileExists checks if the specified path is a file, or not. If the file doesn't exist, it returns false, nil

func FilesEqual

func FilesEqual(a, b File) bool

unique ~~~~

func HasSuffix

func HasSuffix(file, suffix string) bool

func JoinDirs

func JoinDirs(dirs ...string) (dirPath string)

func MakeDirectory

func MakeDirectory(path string) error

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

func PathIsDir(path string) bool

Checks if the path specified is that of a directory. Returns false if the path string is an empty string.

func ReadDirectory

func ReadDirectory(dirPath string) (entries []fs.DirEntry)

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 SetDebug

func SetDebug(newDB bool)

func SplitDirectories

func SplitDirectories(filePath string) (dirs []string, filename string)

This will split up a file path into it's constituting directories, and filename.

func SplitFileName

func SplitFileName(filename string) (name, filetype string)

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

func SplitFilePath(filePath string) (path, filename string)

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 ValidDirectoryName(dir string) (isValid bool)

func ValidFileName

func ValidFileName(filename string) (isValid bool)

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

  1. Calling file.Write(byteArr) will write directly the contents of the byte array into the file.
  2. 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

func NewFile(filePath string) *File

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

func OpenFile(path string) (f *File, err error)

Loads file from memory, loading any contents into the file created. The intended way to create files if they exist within memory.

func (*File) Append

func (f *File) Append(bytes []byte)

Appends to the end of the buffer.

func (*File) ClearFile

func (f *File) ClearFile() error

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) Contents

func (f *File) Contents() []byte

Returns the contents stored in the file buffer.

func (File) FullName

func (f File) FullName() string

func (*File) IsEmpty

func (f *File) IsEmpty() bool

Returns if the file buffer is empty.

func (*File) Name

func (f *File) Name() string

Returns the file name.

func (*File) Path

func (f *File) Path() string

Returns the directory of the specified file. Promise: Must end with a '/'

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

Fulfills io.Reader interface. Reads the file, and returns the number of bytes read.

func (*File) ReadContents

func (f *File) ReadContents() ([]byte, error)

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) Rename

func (f *File) Rename(path, name string)

Renames the filename of the file object.

func (*File) String

func (f *File) String() string

Returns Important information about the file to be able to gather more information when printing.

func (*File) Write

func (f *File) Write(p []byte) (n int, err error)

Fulfills io.Writer interface. Writes to the file, appending the given bytes.

func (*File) WriteContents

func (f *File) WriteContents() error

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 NewTextFile(filePath string) *TextFile

func (*TextFile) Append

func (f *TextFile) Append(s string)

func (*TextFile) AppendEmptyLine

func (t *TextFile) AppendEmptyLine()

func (*TextFile) AppendLastLine

func (t *TextFile) AppendLastLine(s string)

This adds the specified line at the end of the text. If

func (*TextFile) AppendLines

func (t *TextFile) AppendLines(arr []string)

func (*TextFile) AppendNewLine

func (f *TextFile) AppendNewLine(s string)

func (*TextFile) Contents

func (f *TextFile) Contents() []string

func (*TextFile) ReadContents

func (t *TextFile) ReadContents() ([]string, error)

func (*TextFile) ReadLine

func (t *TextFile) ReadLine(lineNum int) (output string, err error)

func (*TextFile) SetLine

func (t *TextFile) SetLine(s string, i int)

func (*TextFile) WriteContents

func (t *TextFile) WriteContents()

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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