file

package
v0.4.131 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 24 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const NoFollow = syscall.O_NOFOLLOW

NoFollow is the open flag that refuses a symlink as the last name (ELOOP).

Variables

View Source
var ErrHoldsMountPoint = errors.New("a disk or a share is mounted there")

ErrHoldsMountPoint is the error of RemoveAllNoCross when a disk or a share is mounted in the tree.

View Source
var ErrLinkOutside = errors.New("a link out of the managed file roots: skipped")

ErrLinkOutside is the error of a copy that skipped a link inside the copied folder that leads out of file ManagementRoots (copying it would bring what it points to inside).

View Source
var ErrNotRegular = errors.New("not a regular file: skipped")

ErrNotRegular is the error of a copy that skipped what is not a regular file.

Functions

func CheckNoMountPoint added in v0.4.82

func CheckNoMountPoint(path string) error

CheckNoMountPoint is the rule of RemoveAllNoCross: ErrHoldsMountPoint when a disk or a share is mounted at the folder path or under it.

func CheckNotExist

func CheckNotExist(src string) bool

CheckNotExist check if the file exists

func CheckPermission

func CheckPermission(src string) bool

CheckPermission check if the file has permission

func CommonPrefix

func CommonPrefix(sep byte, paths ...string) string

func ComparisonHash

func ComparisonHash(data []byte, hash string) bool

Comparison data hash

func CopyDir

func CopyDir(src string, dst string, style string) error

Dir copies a whole directory recursively

func CopyDirContext added in v0.4.82

func CopyDirContext(ctx context.Context, src, dst, style string) error

CopyDirContext is CopyDir that stops when ctx is done, between files and inside them.

func CopyInRoots added in v0.4.118

func CopyInRoots(ctx context.Context, src *os.Root, srcRel string, dst *os.Root, dstDir, style string) error

CopyInRoots copies srcRel of src into the folder dstDir of dst, under its own name, as CopyDirContext does. A link is copied as what it points to when that stays inside src, skipped otherwise (ErrLinkOutside, said at the end, as a device or a pipe is, ErrNotRegular). style "skip" leaves a file already there; anything else overwrites it.

func CopyInRootsAs added in v0.4.118

func CopyInRootsAs(ctx context.Context, src *os.Root, srcRel string, dst *os.Root, dstRel, style string) error

CopyInRootsAs is CopyInRoots to the name dstRel itself.

func CopySingleFile

func CopySingleFile(src, dst, style string) error

*

  • @description:
  • @param {*} src
  • @param {*} dst
  • @param {string} style
  • @return {*}
  • @method:
  • @router:

func CreateFile

func CreateFile(path string) error

func CreateFileAndWriteContent

func CreateFileAndWriteContent(path string, content string) error

func DataLength

func DataLength(length int) []byte

get data byte length

func DirSizeB

func DirSizeB(path string) (int64, error)

getFileSize get file size by path(B)

func Exists

func Exists(path string) bool

判断所给路径文件/文件夹是否存在

func GetBlockInfo

func GetBlockInfo(fileSize int64) (blockSize int, length int)

Get info of block

func GetExt

func GetExt(fileName string) string

GetExt get the file ext

func GetFileOrDirSize

func GetFileOrDirSize(path string) (int64, error)

func GetHashByContent

func GetHashByContent(data []byte) string

get the hash of the data

func GetHashByPath

func GetHashByPath(path string) string

get the hash of the data

func GetImage

func GetImage(path string, width, height int) ([]byte, error)

func GetImageExt

func GetImageExt(p string) (string, error)

* * @description:get a image's ext * @param {string} path "file path" * @return {string} ext "file ext" * @return {error} err "error info"

func GetImageExtByName

func GetImageExtByName(p string) (string, error)

func GetImageNamed added in v0.4.118

func GetImageNamed(path, name string, width, height int) ([]byte, error)

GetImageNamed is GetImage of the file at path, whose format is told by name (path may be a /proc/self/fd/N that has none).

func GetNoDuplicateFileName

func GetNoDuplicateFileName(fullPath string) string

Check for duplicate file names

func GetSize

func GetSize(f multipart.File) (int, error)

GetSize get the file size

func GetThumbnailByOwnerPhotos

func GetThumbnailByOwnerPhotos(path string) ([]byte, error)

func GetThumbnailByWebPhoto

func GetThumbnailByWebPhoto(path string, width, height int) ([]byte, error)

func ImageExtArray

func ImageExtArray() []string

func IsDir

func IsDir(path string) bool

判断所给路径是否为文件夹

func IsFile

func IsFile(path string) bool

判断所给路径是否为文件

func IsNotExistCreateFile

func IsNotExistCreateFile(src string) error

IsNotExistCreateFile create a file if it does not exist

func IsNotExistMkDir

func IsNotExistMkDir(src string) error

IsNotExistMkDir create a directory if it does not exist

func MkDir

func MkDir(src string) error

MkDir create a directory

func MoveFile

func MoveFile(sourcePath, destPath string) error

func MustOpen

func MustOpen(fileName, filePath string) (*os.File, error)

MustOpen maximize trying to open the file

func NameAccumulation

func NameAccumulation(name string, dir string) string

func Open

func Open(name string, flag int, perm os.FileMode) (*os.File, error)

Open a file according to a specific mode

func Overlap added in v0.4.82

func Overlap(from, to string) bool

Overlap reports whether copying or moving from into the folder to would write over from or into it: the entry it makes, to/<name of from>, is from or holds it, or to is from or inside it. Paths are compared with their links resolved, and as files where they exist: a bind mount gives a folder a second name that no path comparison sees.

func ParseFileHeader

func ParseFileHeader(h []byte, boundary []byte) (map[string]string, bool)

func ParseFromHead

func ParseFromHead(read_data []byte, read_total int, boundary []byte, stream io.ReadCloser) (map[string]string, []byte, error)

func PrefixLength

func PrefixLength(byteLength int) []byte

get prefix byte length

func RMDir

func RMDir(src string) error

RMDir remove a directory

func ReadFullFile

func ReadFullFile(path string) []byte

func ReadLine

func ReadLine(lineNumber int, path string) string

func ReadToBoundary

func ReadToBoundary(boundary []byte, stream io.ReadCloser, target io.WriteCloser) ([]byte, bool, error)

func RemoveAll

func RemoveAll(dir string) error

func RemoveAllNoCross added in v0.4.82

func RemoveAllNoCross(path string) error

RemoveAllNoCross is os.RemoveAll that never goes into a mounted disk or share: when one is mounted at path or under it, it removes nothing.

func ReplaceFile added in v0.4.82

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

ReplaceFile is ReplaceFileFrom for data.

func ReplaceFileFrom added in v0.4.82

func ReplaceFileFrom(path string, r io.Reader) error

ReplaceFileFrom writes what it reads from r over an existing file as WriteFileAtomic does, for a file someone edits or sends again: through a link it writes the link's target, the new file keeps the old one's mode and owner, and a file with hard links is written in place.

func SizeIn added in v0.4.118

func SizeIn(root *os.Root, rel string) (int64, error)

SizeIn is the size of rel below root, a folder counted with all it holds: entries are measured as they are (Lstat), links not followed, and nothing is read outside root.

func SpliceFiles

func SpliceFiles(dir, path string, length int, startPoint int) error

func WriteFileAtomic added in v0.4.62

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

WriteFileAtomic writes data to a temporary file next to path, syncs it to disk and renames it over path: after a power cut (common on single-board boxes) the file holds the old content or the new one, never an empty one. os.CreateTemp creates it 0600, whatever the old file's mode: it is for root's own state files.

func WriteFileAtomicFrom added in v0.4.82

func WriteFileAtomicFrom(path string, r io.Reader, perm os.FileMode) error

WriteFileAtomicFrom is WriteFileAtomic for the content read from r, the new file made perm.

func WriteToFullPath

func WriteToFullPath(data []byte, fullPath string, perm fs.FileMode) error

func WriteToPath

func WriteToPath(data []byte, path, name string) error

Types

type ReadLineFromEnd

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

ReadLineFromEnd --

func NewReadLineFromEnd

func NewReadLineFromEnd(name string) (rd *ReadLineFromEnd, err error)

NewReadLineFromEnd --

func (*ReadLineFromEnd) Close

func (c *ReadLineFromEnd) Close() (err error)

Close --

func (*ReadLineFromEnd) ReadLine

func (c *ReadLineFromEnd) ReadLine() (line []byte, err error)

ReadLine 结尾包含'\n'

Jump to

Keyboard shortcuts

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