Documentation
¶
Index ¶
- Variables
- func Abs(path string) string
- func Basename(path string) string
- func Chdir(dir string) error
- func Chmod(path string, mode os.FileMode) error
- func Create(path string) (*os.File, error)
- func Dir(path string) string
- func DirNames(path string) ([]string, error)
- func Exists(path string) bool
- func Ext(path string) string
- func ExtName(path string) string
- func FormatSize(raw int64) string
- func GetBytes(path string) []byte
- func GetBytesByTwoOffsets(reader io.ReaderAt, start int64, end int64) []byte
- func GetBytesByTwoOffsetsByPath(path string, start int64, end int64) []byte
- func GetBytesTilChar(reader io.ReaderAt, char byte, start int64) ([]byte, int64)
- func GetBytesTilCharByPath(path string, char byte, start int64) ([]byte, int64)
- func GetContents(path string) string
- func GetNextCharOffset(reader io.ReaderAt, char byte, start int64) int64
- func GetNextCharOffsetByPath(path string, char byte, start int64) int64
- func Glob(pattern string, onlyNames ...bool) ([]string, error)
- func Home(names ...string) (string, error)
- func Info(path string) (os.FileInfo, error)
- func IsDir(path string) bool
- func IsEmpty(path string) bool
- func IsFile(path string) bool
- func IsReadable(path string) bool
- func IsWritable(path string) bool
- func MTime(path string) time.Time
- func MTimestamp(path string) int64
- func MTimestampMilli(path string) int64
- func Mkdir(path string) error
- func Move(src string, dst string) error
- func Name(path string) string
- func Open(path string) (*os.File, error)
- func OpenFile(path string, flag int, perm os.FileMode) (*os.File, error)
- func OpenWithFlag(path string, flag int) (*os.File, error)
- func OpenWithFlagPerm(path string, flag int, perm os.FileMode) (*os.File, error)
- func PutBytes(path string, content []byte) error
- func PutBytesAppend(path string, content []byte) error
- func PutContents(path string, content string) error
- func PutContentsAppend(path string, content string) error
- func Pwd() string
- func ReadByteLines(file string, callback func(bytes []byte) error) error
- func ReadLines(file string, callback func(text string) error) error
- func ReadLinesBytes(file string, callback func(bytes []byte) error) error
- func ReadableSize(path string) string
- func RealPath(path string) string
- func Remove(path string) error
- func Rename(src string, dst string) error
- func SelfDir() string
- func SelfName() string
- func SelfPath() string
- func Size(path string) int64
- func SizeFormat(path string) string
- func Stat(path string) (os.FileInfo, error)
- func StrToSize(sizeStr string) int64
- func Truncate(path string, size int) error
Constants ¶
This section is empty.
Variables ¶
var ( // Separator for file system. // It here defines the separator as variable // to allow it modified by developer if necessary. Separator = string(filepath.Separator) // DefaultPerm is the default perm for file opening. DefaultPermOpen = os.FileMode(0666) // DefaultPermCopy is the default perm for file/folder copy. DefaultPermCopy = os.FileMode(0777) )
var (
// DefaultReadBuffer is the buffer size for reading file content.
DefaultReadBuffer = 1024
)
Functions ¶
func Abs ¶
Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.
func Basename ¶
Basename returns the last element of path, which contains file extension. Trailing path separators are removed before extracting the last element. If the path is empty, Base returns ".". If the path consists entirely of separators, Basename returns a single separator. Example: /var/www/file.js -> file.js file.js -> file.js
func Chdir ¶
Chdir changes the current working directory to the named directory. If there is an error, it will be of type *PathError.
func Create ¶
Create creates file with given <path> recursively. The parameter <path> is suggested to be absolute path.
func Dir ¶
Dir returns all but the last element of path, typically the path's directory. After dropping the final element, Dir calls Clean on the path and trailing slashes are removed. If the `path` is empty, Dir returns ".". If the `path` is ".", Dir treats the path as current working directory. If the `path` consists entirely of separators, Dir returns a single separator. The returned path does not end in a separator unless it is the root directory.
func DirNames ¶
DirNames returns sub-file names of given directory <path>. Note that the returned names are NOT absolute paths.
func Ext ¶
Ext returns the file name extension used by path. The extension is the suffix beginning at the final dot in the final element of path; it is empty if there is no dot.
Note: the result contains symbol '.'.
func ExtName ¶
ExtName is like function Ext, which returns the file name extension used by path, but the result does not contains symbol '.'.
func FormatSize ¶
FormatSize formats size <raw> for more human readable.
func GetBytes ¶
GetBytes returns the file content of <path> as []byte. It returns nil if it fails reading.
func GetBytesByTwoOffsets ¶
GetBytesByTwoOffsets returns the binary content as []byte from <start> to <end>. Note: Returned value does not contain the character of the last position, which means it returns content range as [start, end).
func GetBytesByTwoOffsetsByPath ¶
GetBytesByTwoOffsetsByPath returns the binary content as []byte from <start> to <end>. Note: Returned value does not contain the character of the last position, which means it returns content range as [start, end). It opens file of <path> for reading with os.O_RDONLY flag and default perm.
func GetBytesTilChar ¶
GetBytesTilChar returns the contents of the file as []byte until the next specified byte <char> position.
Note: Returned value contains the character of the last position.
func GetBytesTilCharByPath ¶
GetBytesTilCharByPath returns the contents of the file given by <path> as []byte until the next specified byte <char> position. It opens file of <path> for reading with os.O_RDONLY flag and default perm.
Note: Returned value contains the character of the last position.
func GetContents ¶
GetContents returns the file content of <path> as string. It returns en empty string if it fails reading.
func GetNextCharOffset ¶
GetNextCharOffset returns the file offset for given <char> starting from <start>.
func GetNextCharOffsetByPath ¶
GetNextCharOffsetByPath returns the file offset for given <char> starting from <start>. It opens file of <path> for reading with os.O_RDONLY flag and default perm.
func Glob ¶
Glob returns the names of all files matching pattern or nil if there is no matching file. The syntax of patterns is the same as in Match. The pattern may describe hierarchical names such as /usr/*/bin/ed (assuming the Separator is '/').
Glob ignores file system errors such as I/O errors reading directories. The only possible returned error is ErrBadPattern, when pattern is malformed.
func Home ¶
Home returns absolute path of current user's home directory. The optional parameter <names> specifies the its sub-folders/sub-files, which will be joined with current system separator and returned with the path.
func IsDir ¶
IsDir checks whether given <path> a directory. Note that it returns false if the <path> does not exist.
func IsEmpty ¶
IsEmpty checks whether the given <path> is empty. If <path> is a folder, it checks if there's any file under it. If <path> is a file, it checks if the file size is zero.
Note that it returns true if <path> does not exist.
func IsFile ¶
IsFile checks whether given <path> a file, which means it's not a directory. Note that it returns false if the <path> does not exist.
func IsReadable ¶
IsReadable checks whether given <path> is readable.
func IsWritable ¶
IsWritable checks whether given <path> is writable.
TODO improve performance; use golang.org/x/sys to cross-plat-form
func MTimestamp ¶
MTimestamp returns the modification time of file given by <path> in second.
func MTimestampMilli ¶
MTimestampMilli returns the modification time of file given by <path> in millisecond.
func Mkdir ¶
Mkdir creates directories recursively with given <path>. The parameter <path> is suggested to be an absolute path instead of relative one.
func Move ¶
Move renames (moves) <src> to <dst> path. If <dst> already exists and is not a directory, it'll be replaced.
func Name ¶
Name returns the last element of path without file extension. Example: /var/www/file.js -> file file.js -> file
func OpenFile ¶
OpenFile opens file/directory with custom <flag> and <perm>. The parameter <flag> is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc.
func OpenWithFlag ¶
OpenWithFlag opens file/directory with default perm and custom <flag>. The default <perm> is 0666. The parameter <flag> is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc.
func OpenWithFlagPerm ¶
OpenWithFlagPerm opens file/directory with custom <flag> and <perm>. The parameter <flag> is like: O_RDONLY, O_RDWR, O_RDWR|O_CREATE|O_TRUNC, etc. The parameter <perm> is like: 0600, 0666, 0777, etc.
func PutBytes ¶
PutBytes puts binary <content> to file of <path>. It creates file of <path> recursively if it does not exist.
func PutBytesAppend ¶
PutBytesAppend appends binary <content> to file of <path>. It creates file of <path> recursively if it does not exist.
func PutContents ¶
PutContents puts string <content> to file of <path>. It creates file of <path> recursively if it does not exist.
func PutContentsAppend ¶
PutContentsAppend appends string <content> to file of <path>. It creates file of <path> recursively if it does not exist.
func Pwd ¶
func Pwd() string
Pwd returns absolute path of current working directory. Note that it returns an empty string if retrieving current working directory failed.
func ReadByteLines ¶
ReadByteLines reads file content line by line, which is passed to the callback function <callback> as []byte. It matches each line of text, separated by chars '\r' or '\n', stripped any trailing end-of-line marker.
Note that the parameter passed to callback function might be an empty value, and the last non-empty line will be passed to callback function <callback> even if it has no newline marker.
Deprecated, use ReadLinesBytes instead.
func ReadLines ¶
ReadLines reads file content line by line, which is passed to the callback function <callback> as string. It matches each line of text, separated by chars '\r' or '\n', stripped any trailing end-of-line marker.
Note that the parameter passed to callback function might be an empty value, and the last non-empty line will be passed to callback function <callback> even if it has no newline marker.
func ReadLinesBytes ¶
ReadLinesBytes reads file content line by line, which is passed to the callback function <callback> as []byte. It matches each line of text, separated by chars '\r' or '\n', stripped any trailing end-of-line marker.
Note that the parameter passed to callback function might be an empty value, and the last non-empty line will be passed to callback function <callback> even if it has no newline marker.
func ReadableSize ¶
ReadableSize formats size of file given by <path>, for more human readable.
func RealPath ¶
RealPath converts the given <path> to its absolute path and checks if the file path exists. If the file does not exist, return an empty string.
func Remove ¶
Remove deletes all file/directory with <path> parameter. If parameter <path> is directory, it deletes it recursively.
func SelfDir ¶
func SelfDir() string
SelfDir returns absolute directory path of current running process(binary).
func SelfName ¶
func SelfName() string
SelfName returns file name of current running process(binary).
func SelfPath ¶
func SelfPath() string
SelfPath returns absolute file path of current running process(binary).
func SizeFormat ¶
SizeFormat returns the size of file specified by <path> in format string.
func Stat ¶
Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.
Types ¶
This section is empty.