file

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2025 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(data string, dst string) (err error)

Append appends a string to the end of file dst.

func CommandExists

func CommandExists(name string) (bool, error)

func Copy

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

Copy copies a file from src to dst, creating directories for the destination if needed. dst is assumed to be a file and not a directory. Will preserve permissions.

func CopyDir

func CopyDir(src, dst string, newDirPermissions, childFilePermissions fs.FileMode, mergedDirPermissions *fs.FileMode) (err error)

CopyDir copies src directory to dst, creating the dst directory if needed. dst is assumed to be a directory and not a file.

func CopyResourceFile

func CopyResourceFile(srcFS fs.FS, srcFile, dst string, dirmode os.FileMode, filemode os.FileMode) error

CopyResourceFile copies a file from an embedded binary resource file to disk. This will override any existing file.

func Create

func Create(dst string, perm os.FileMode) (err error)

Create creates a new file with the provided Unix permissions

func CreateDestinationDir

func CreateDestinationDir(dst string, dirmode os.FileMode) (err error)

func DirExists

func DirExists(path string) (exists bool, err error)

DirExists returns true if the directory exists, false otherwise.

func EnumerateDirFiles

func EnumerateDirFiles(dirPath string) (filePaths []string, err error)

func GenerateSHA1

func GenerateSHA1(path string) (hash string, err error)

GenerateSHA1 calculates a sha1 of a file

func GenerateSHA256

func GenerateSHA256(path string) (hash string, err error)

GenerateSHA256 calculates a sha256 of a file

func GetAbsPathWithBase

func GetAbsPathWithBase(baseDirPath, inputPath string) string

GetAbsPathWithBase converts 'inputPath' to an absolute path starting from 'baseDirPath', but only if it wasn't an absolute path in the first place.

func IsDir

func IsDir(filePath string) (isDir bool, err error)

IsDir check if a given file path is a directory.

func IsDirEmpty

func IsDirEmpty(path string) (bool, error)

func IsFile

func IsFile(path string) (isFile bool, err error)

IsFile returns true if the provided path is a file.

func IsFileOrSymlink(path string) (isFile bool, err error)

IsFileOrSymlink returns true if the provided path is a file or a symlink.

func Move

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

Move moves a file from src to dst. Will preserve permissions.

func PathExists

func PathExists(path string) (exists bool, err error)

PathExists returns true if the path exists, false otherwise.

func Read

func Read(src string) (data string, err error)

Read reads a string from the file src.

func ReadLines

func ReadLines(path string) (lines []string, err error)

readLines reads file under path and returns lines as strings and any error encountered

func RemoveDirectoryContents

func RemoveDirectoryContents(path string) (err error)

RemoveDirectoryContents will delete the contents of a directory, but not the directory itself. If the directory does not exist, it will return an error.

func RemoveFileIfExists

func RemoveFileIfExists(path string) (err error)

RemoveFileIfExists will delete a file if it exists on disk.

func Write

func Write(data string, dst string) (err error)

Write writes a string to the file dst.

func WriteLines

func WriteLines(dataLines []string, destinationPath string) (err error)

WriteLines writes each string to the same file, separated by lineSeparator (e.g. "\n").

func WriteWithPerm

func WriteWithPerm(data string, dst string, perm os.FileMode) (err error)

Types

type FileCopyBuilder

type FileCopyBuilder struct {
	Src            string
	Dst            string
	DirFileMode    os.FileMode
	ChangeFileMode bool
	FileMode       os.FileMode
	NoDereference  bool
}

func NewFileCopyBuilder

func NewFileCopyBuilder(src string, dst string) FileCopyBuilder

func (FileCopyBuilder) Run

func (b FileCopyBuilder) Run() (err error)

func (FileCopyBuilder) SetDirFileMode

func (b FileCopyBuilder) SetDirFileMode(dirFileMode os.FileMode) FileCopyBuilder

func (FileCopyBuilder) SetFileMode

func (b FileCopyBuilder) SetFileMode(fileMode os.FileMode) FileCopyBuilder

func (FileCopyBuilder) SetNoDereference

func (b FileCopyBuilder) SetNoDereference() FileCopyBuilder

Jump to

Keyboard shortcuts

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