files

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2019 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package files provides standard file functions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIfExists

func CheckIfExists(dir string) bool

CheckIfExists checks if a file / directory exists

func CopyFileContents

func CopyFileContents(src, dst string) (err error)

CopyFileContents writes the contents from src to a new file dst. This operation is silently destructive

func CreateDirsIfNotExists

func CreateDirsIfNotExists(d []string) error

CreateDirsIfNotExists takes an array of strings containing filepaths and for any path that contains directories which do not exist, it creates them.

func DownloadFile

func DownloadFile(url string, writefile string, interactive bool) error

DownloadFile downs a file from a URL and writes it to disk

func LoadToml

func LoadToml(tomlFile string) (*toml.Tree, error)

LoadToml loads a Toml file and returns a tree object.

func ProcessFileOptions added in v0.3.0

func ProcessFileOptions(filename string, options Bits) error

ProcessFileOptions decides what to do with an existing file before any modifications (create, copy, move, delete, update), based on the options provided. If the OverwriteSilently bit is set, this function does nothing, allowing the file to be silently modified later. Otherwise, if the PromptIfExisting bit is set, the user is interactively prompted for confirmation (yes/no). If the BackupExisting flag is set, the file is also backed-up.

func SafeRename added in v0.3.0

func SafeRename(origDir string) error

SafeRename renames a folder or file to <name>.~n~ where n is the lowest value where the folder does not already exist. The value of n is capped at 100, which would require the user to manually tidy the parent folder.

func SaveToml

func SaveToml(tree *toml.Tree, tomlFile string) error

SaveToml writes a tree object (back) to a toml file

func WriteToFile

func WriteToFile(filename string, data string, options Bits) error

WriteToFile calls ProcessFileOptions before writing a string variable to a file.

func WriteToFilePrivate

func WriteToFilePrivate(filename string, data string) error

WriteToFilePrivate writes a string variable to a file with 0600 permissions. It creates all directories along the path if they don't exist.

Types

type Bits added in v0.3.0

type Bits uint8

Bits is used to hold bitwise options

const (
	BackupExisting Bits = 1 << iota
	PromptIfExisting
	OverwriteSilently
)

File options

Jump to

Keyboard shortcuts

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