fileutils

package
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	B  Fsize = 1
	KB       = 1024 * B
	MB       = 1024 * KB
	GB       = 1024 * MB
)
View Source
const BufferSize = 8 * 1024 * 1024

BufferSize defines the buffer size when reading and writing file.

Variables

This section is empty.

Functions

func CopyFile

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

CopyFile copies the file src to dst.

func CreateDirectory

func CreateDirectory(dirPath string) error

CreateDirectory creates directory recursively.

func DeleteFile

func DeleteFile(filePath string) error

DeleteFile deletes a file not a directory.

func DeleteFiles

func DeleteFiles(filePaths ...string)

DeleteFiles deletes all the given files.

func FsizeToString added in v1.0.0

func FsizeToString(fsize Fsize) string

FsizeToString parses a Fsize value into string.

func GetMd5Sum added in v1.0.0

func GetMd5Sum(md5 hash.Hash, b []byte) string

GetMd5Sum gets md5 sum as a string and appends the current hash to b.

func GetSys

func GetSys(info os.FileInfo) (*syscall.Stat_t, bool)

GetSys returns the underlying data source of the os.FileInfo.

func IsDir

func IsDir(name string) bool

IsDir reports whether the path is a directory.

func IsEmptyDir added in v1.0.3

func IsEmptyDir(path string) (bool, error)

IsEmptyDir check whether the directory is empty.

func IsRegularFile

func IsRegularFile(name string) bool

IsRegularFile reports whether the file is a regular file. If the given file is a symbol link, it will follow the link.

func Link(src string, linkName string) error

Link creates a hard link pointing to src named linkName for a file.

func LoadYaml

func LoadYaml(path string, out interface{}) error

LoadYaml loads yaml config file.

func Md5Sum

func Md5Sum(name string) string

Md5Sum generates md5 for a given file.

func MoveFile

func MoveFile(src string, dst string) error

MoveFile moves the file src to dst.

func MoveFileAfterCheckMd5

func MoveFileAfterCheckMd5(src string, dst string, md5 string) error

MoveFileAfterCheckMd5 will check whether the file's md5 is equals to the param md5 before move the file src to dst.

func OpenFile

func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)

OpenFile opens a file. If the parent directory of the file isn't exist, it will create the directory.

func PathExist

func PathExist(name string) bool

PathExist reports whether the path is exist. Any error get from os.Stat, it will return false.

func SymbolicLink(src string, target string) error

SymbolicLink creates target as a symbolic link to src.

Types

type FileLock added in v1.0.0

type FileLock struct {
	// contains filtered or unexported fields
}

FileLock defines a file lock implemented by syscall.Flock

func NewFileLock added in v1.0.0

func NewFileLock(name string) *FileLock

NewFileLock create a FileLock instance

func (*FileLock) Lock added in v1.0.0

func (l *FileLock) Lock() error

Lock locks file. If the file is already locked, the calling goroutine blocks until the file is unlocked. If lock has been invoked without unlock, lock again will return an error.

func (*FileLock) Unlock added in v1.0.0

func (l *FileLock) Unlock() error

Unlock unlocks file. If lock has not been invoked before unlock, unlock will return an error.

type Fsize added in v1.0.0

type Fsize int64

Fsize is a wrapper type which indicates the file size.

func GetFreeSpace added in v1.0.0

func GetFreeSpace(path string) (Fsize, error)

GetFreeSpace gets the free disk space of the path.

func StringToFSize added in v1.0.0

func StringToFSize(fsize string) (Fsize, error)

StringToFSize parses a string into Fsize.

func (Fsize) MarshalYAML added in v1.0.0

func (f Fsize) MarshalYAML() (interface{}, error)

MarshalYAML implements the yaml.Marshaler interface.

func (*Fsize) UnmarshalYAML added in v1.0.0

func (f *Fsize) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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