fs

package
v0.6.0-dev.7 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Determined/Provided Paths
	Home      Folder // ApplicationDocumentsDir on Mobile, HOME_DIR on Desktop
	Support   Folder // AppSupport Directory
	Temporary Folder // AppCache Directory

	// Calculated Paths
	Database   Folder // Device DB Folder
	Downloads  Folder // Temporary Directory on Mobile for Export, Downloads on Desktop
	Wallet     Folder // Encrypted Storage Directory
	ThirdParty Folder // Sub-Directory of Support, used for Textile

	// Path Manipulation Errors
	ErrDuplicateFilePathOption    = errors.New("Duplicate file path option")
	ErrPrefixSuffixSetWithReplace = errors.New("Prefix or Suffix set with Replace.")
	ErrSeparatorLength            = errors.New("Separator length must be 1.")
	ErrNoFileNameSet              = errors.New("File name was not set by options.")

	// Device ID Errors
	ErrEmptyDeviceID = errors.New("Device ID cannot be empty")
	ErrMissingEnvVar = errors.New("Cannot set EnvVariable with empty value")

	// Directory errors
	ErrDirectoryInvalid = errors.New("Directory Type is invalid")
	ErrDirectoryUnset   = errors.New("Directory path has not been set")
	ErrDirectoryJoin    = errors.New("Failed to join directory path")
)

Functions

func Exists

func Exists(fileName string) bool

Exists checks if a file exists.

func IsFile

func IsFile(fileName string) bool

IsFile returns true if the given path is a file

Types

type FilePathOptFunc

type FilePathOptFunc func(path string) FilePathOption

FilePathOptFunc is a function that returns a FilePathOption.

var WithPrefix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypePrefix,
		value:           path,
	}
}

WithPrefix sets the prefix for the file path.

var WithReplace FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeReplace,
		value:           path,
	}
}

WithReplace sets the replace string for the file path.

var WithSeparator FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSeparator,
		value:           path,
	}
}

WithSeparator sets the separator for the file path.

var WithSuffix FilePathOptFunc = func(path string) FilePathOption {
	return &filePathOpt{
		filePathOptType: filePathOptionTypeSuffix,
		value:           path,
	}
}

WithSuffix sets the suffix for the file path.

type FilePathOption

type FilePathOption interface {
	Apply() *filePathOptions
}

FilePathOption is a function option for FilePath.

type Folder

type Folder string

func (Folder) Create

func (f Folder) Create(fileName string) (*os.File, error)

Create creates a file.

func (Folder) CreateFolder

func (f Folder) CreateFolder(dirName string) (Folder, error)

CreateFolder creates a folder.

func (Folder) Delete

func (f Folder) Delete(fileName string) error

Delete removes a file or a folder.

func (Folder) Exists

func (f Folder) Exists(fileName string) bool

Exists checks if a file exists.

func (Folder) GenPath

func (f Folder) GenPath(path string, opts ...FilePathOption) (string, error)

GenPath generates a path from a folder and a file name.

func (Folder) JoinPath

func (f Folder) JoinPath(ps ...string) string

JoinPath joins a folder and a file name.

func (Folder) MkdirAll

func (f Folder) MkdirAll() error

MkdirAll creates a directory and all its parents.

func (Folder) Path

func (f Folder) Path() string

Path returns the path of the folder.

func (Folder) ReadFile

func (f Folder) ReadFile(fileName string) ([]byte, error)

ReadFile reads a file.

func (Folder) WriteFile

func (f Folder) WriteFile(fileName string, data []byte) error

WriteFile writes a file.

Jump to

Keyboard shortcuts

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