file

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MulanPSL-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToFile

func BytesToFile(path string, data []byte) error

BytesToFile writes data to a file. If the file does not exist it will be created with permission mode 0644.

func ClearFile

func ClearFile(path string) error

ClearFile clears a file content.

func Create

func Create(path string) (*os.File, error)

Create creates or truncates file specified by path. If the file already exists, it is truncated. If the parent directory does not exist, it will be created with mode os.ModePerm(0777). If the file does not exist, it is created with mode 0666. If successfully called Create, the returned file can be used for I/O and the associated file descriptor has mode O_RDWR.

func CreateFile

func CreateFile(path string) error

CreateFile creates a file specified by path. If the file already exists, it is truncated. If the parent directory does not exist, it will be created with mode os.ModePerm(0777).

func FileMd5

func FileMd5(path string) (string, error)

FileMd5 gets file MD5.

func FileMd5Reader

func FileMd5Reader(r io.Reader) (string, error)

FileMd5Reader gets file MD5 from io.Reader.

func FileSize

func FileSize(path string) (int64, error)

FileSize gets file size in bytes.

func FileSizeFile

func FileSizeFile(file *os.File) (int64, error)

FileSizeFile gets file size from os.File in bytes.

func FileToBytes

func FileToBytes(path string) []byte

FileToBytes serialize the file to bytes.

func IsDir

func IsDir(path string) bool

IsDir checks whether a path is a directory. If the path is a symbolic link will follow it.

func IsDirE

func IsDirE(path string) (bool, error)

IsDirE checks whether a path is a directory with error. If the path is a symbolic link will follow it.

func IsExist

func IsExist(path string) (bool, error)

IsExist checks whether the file or directory exists. Use os.Stat to get the info of the target file or dir to check whether exists. If os.Stat returns nil err, the target exists. If os.Stat returns a os.ErrNotExist err, the target does not exist. If the error returned is another type, the target is uncertain whether exists.

func IsFile

func IsFile(path string) bool

IsFile checks whether a path is a file. If the path is a symbolic link will follow it.

func IsFileE

func IsFileE(path string) (bool, error)

IsFileE checks whether a path is a file with error. If the path is a symbolic link will follow it.

func IsShortcut

func IsShortcut(path string) bool

IsShortcut checks a file whether is a shortcut on Windows.

func IsSymlink(path string) bool

IsSymlink checks a file whether is a symbolic link on Linux. Note that this doesn't work for the shortcut file on windows. If you want to check a file whether is a shortcut file on Windows please use IsShortcut function.

func IsSymlinkE

func IsSymlinkE(path string) (bool, error)

IsSymlinkE checks a file whether is a symbolic link on Linux. Note that this doesn't work for the shortcut file on windows. If you want to check a file whether is a shortcut file on Windows please use IsShortcut function.

func ListDir

func ListDir(dir string) ([]string, error)

ListDir lists all the file or directory names in the specified directory. Note that ListDir don't traverse recursively.

func ListDirEntryPaths

func ListDirEntryPaths(dir string, cur bool) ([]string, error)

ListDirEntryPaths lists all the file or directory paths in the directory recursively. If the cur is true, result will include current directory. Note that GetDirAllEntryPaths won't follow symlink if the subdir is a symbolic link.

func ListDirEntryPathsSymlink(dirname string, cur bool) ([]string, error)

ListDirEntryPathsSymlink lists all the file or dir paths in the directory recursively. If the cur is true result will include current directory.

func ListFilenames

func ListFilenames(dir string) ([]string, error)

ListFilenames lists all filenames in the specified directory.

func ReadLines

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

ReadLines reads all lines of the file. An error is returned if the specified file does not exist.

func ReadLinesV2

func ReadLinesV2(path string) ([]string, error)

ReadLinesV2 reads all lines of the file. An error is returned if the specified file does not exist.

func ReadLinesV3

func ReadLinesV3(path string) ([]string, error)

ReadLinesV3 reads all lines of the file. An error is returned if the specified file does not exist.

Types

This section is empty.

Jump to

Keyboard shortcuts

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