file

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: BSD-2-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbsPath

func AbsPath(filePath string) (string, error)

AbsPath returns an absolute representation of file path.

func Append

func Append(fileName string, data []byte, perm ...os.FileMode) error

Append appends data to the end of the file by file name with perm, default perm is 0666. If the file does not exist, Append creates it with permissions perm, otherwise Append appends data to the end of the file.

func Copy

func Copy(srcName, destName string, perm ...os.FileMode) error

Copy copies src file contents to dest file contents with perm, default perm is 0666. If dest file already exists, Copy truncates it before copying.

func Deldir

func Deldir(filePath string) error

Deldir deletes file path and any children it contains. It deletes everything it can but returns the first error it encounters. If the file path does not exist, Deldir does nothing and returns nil.

func DirSize

func DirSize(rootPath string) (fileNum, dirSize int64)

DirSize returns the number of files contained in the dictionary and size in bytes. If the dictionary is empty or does not exist or cannot be accessed, it returns 0, 0.

func Ext

func Ext(fileName string) string

Ext returns the lowercase extension of the file name, excluding the dot.

func Hash

func Hash(fileName string, h hash.Hash) (string, error)

Hash returns the hash string of the file content by file name and hash algorithm.

func IsAbsPath

func IsAbsPath(filePath string) bool

IsAbsPath reports whether the file path is absolute.

func IsDir

func IsDir(filePath string) bool

IsDir reports whether the file path describes a dictionary.

func IsExist

func IsExist(filePath string) bool

IsExist reports whether the file path already exists.

func IsFile

func IsFile(filePath string) bool

IsFile reports whether the file path describes a file.

func MD5

func MD5(fileName string) (string, error)

MD5 returns the MD5 hash string of the file content by file name.

func Mkdir

func Mkdir(filePath string, perm ...os.FileMode) error

Mkdir creates a directory by file path with perm, along with any necessary parents, default perm is 0777. If the file path is already a directory, Mkdir does nothing and returns nil.

func Read

func Read(fileName string) ([]byte, error)

Read reads the file by file name and returns the contents.

func ReadToSlice

func ReadToSlice(fileName string) ([]string, error)

ReadToSlice returns the file contents slice separated by row, and excluding the end-of-line bytes.

func Remove

func Remove(fileName string) error

Remove removes the file or empty directory by file name.

func Rename

func Rename(oldName, newName string) error

Rename renames (moves) old name to new name. If new name already exists and is not a directory, Rename replaces it.

func SHA1

func SHA1(fileName string) (string, error)

SHA1 returns the SHA1 hash string of the file content by file name.

func SHA256

func SHA256(fileName string) (string, error)

SHA256 returns the SHA256 hash string of the file content by file name.

func SHA512

func SHA512(fileName string) (string, error)

SHA512 returns the SHA512 hash string of the file content by file name.

func Size

func Size(fileName string) int64

Size returns the file size in bytes. If the file does not exist or cannot be accessed, it returns -1.

func Write

func Write(fileName string, data []byte, perm ...os.FileMode) error

Write writes data to the file by file name with perm, default perm is 0666. If the file does not exist, Write creates it with permissions perm, otherwise Write truncates it before writing.

Types

This section is empty.

Jump to

Keyboard shortcuts

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