filex

package
v0.0.0-...-419c0c3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidWrite = errors.New("invalid write result")
View Source
var ErrShortWrite = io.ErrShortWrite

Functions

func AbsAll

func AbsAll(paths []string) []string

func Append

func Append(opts *options)

Append 返回一个 Option,用于设置以追加模式写入文件

func CalcSum

func CalcSum(ctx context.Context, fn, hashType string) (digest string, err error)

func Cat

func Cat(filePath string, trimSpace ...bool) string

Cat 一次性读取文件全部内容并以字符串形式返回

func CatE

func CatE(filePath string, trimSpace ...bool) (string, error)

func CheckSum

func CheckSum(ctx context.Context, fn, digest string) bool

func CheckSumE

func CheckSumE(ctx context.Context, fn, digest string) (pass bool, err error)

func CopyPipe

func CopyPipe(ctx context.Context, dst io.Writer, src io.Reader, progress func(int64)) (err error)

func Delete

func Delete(fn string) (err error)

Delete 删除文件或者目录,不存在不报错

func Exists

func Exists(p string) bool

func FileCopy

func FileCopy(src, dst string, opts ...Option) (err error)

func FileInfoAccessTime

func FileInfoAccessTime(fi os.FileInfo) time.Time

func IsRegular

func IsRegular(path string) bool

func List

func List(root string, matches ...func(string, fs.DirEntry) error) (files []string, err error)

func Open

func Open(filePath string, opts ...Option) (file *os.File, err error)

Open 根据 opts 选项打开或创建文件,支持只读、覆盖、追加、排他创建等模式

func OpenRead

func OpenRead(filePath string, processFunc ProcessFunc, opts ...Option) (err error)

func OpenWrite

func OpenWrite(filePath string, processFunc ProcessFunc, opts ...Option) (err error)

func Overwrite

func Overwrite(opts *options)

Overwrite 返回一个 Option,用于设置覆盖已存在的文件

func PathIsDir

func PathIsDir(s string) bool

func PathSplit

func PathSplit(p string) (dir, name, ext string)

func ReaderContext

func ReaderContext(ctx context.Context, r io.Reader) io.Reader

func Readonly

func Readonly(opts *options)

Readonly 返回一个 Option,用于设置以只读方式打开文件

func WriteText

func WriteText(filePath string, text string, opts ...Option) (err error)

WriteText 将文本写入指定文件,支持通过 opts 控制是否自动创建目录及文件权限

Types

type DeleteOptions

type DeleteOptions struct {
	RemoveChildren bool //删除
}

type Option

type Option func(*options)

Option 定义用于配置 options 的函数类型

func CreateDirs

func CreateDirs(createDirs bool, mode os.FileMode) Option

CreateDirs 返回一个 Option,用于设置是否自动创建目录及目录权限

func CreateMode

func CreateMode(mode os.FileMode) Option

CreateMode 返回一个 Option,用于设置创建文件时的权限模式

func Options

func Options(opts ...Option) Option

Options 将多个 Option 合并为一个 Option,便于批量应用

type ProcessFunc

type ProcessFunc func(file *os.File) error

ProcessFunc 定义了对已打开文件进行自定义处理的函数签名

func CalcMD5

func CalcMD5(hexMd5 *string) ProcessFunc

CalcMD5 返回一个 ProcessFunc,用于计算文件 MD5 值并写入 hexMd5 指针指向的字符串

func ReadTo

func ReadTo(ctx context.Context, w io.Writer, progress ...ProgressFunc) ProcessFunc

ReadTo 返回一个 ProcessFunc,用于将文件内容读出到外部 Writer

func WriteFrom

func WriteFrom(ctx context.Context, r io.Reader, progress ...ProgressFunc) ProcessFunc

WriteFrom 返回一个 ProcessFunc,用于将外部 Reader 数据写入文件

type ProgressFunc

type ProgressFunc func(n int64)

ProgressFunc 定义了在拷贝过程中报告已拷贝字节数的函数签名

func ProgressJoin

func ProgressJoin(progress ...ProgressFunc) ProgressFunc

Jump to

Keyboard shortcuts

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