xfile

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2022 License: MulanPSL-2.0 Imports: 9 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(src, dst string, isFirstDel ...bool) (err error)

CopyFile 复制文件

func Create added in v1.0.1

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

Create 可以新建文件/目录

func Exists added in v1.0.1

func Exists(path string) bool

Exists 判断文件/目录是否存在

func GetProjectDir

func GetProjectDir(projectName string) string

GetProjectDir 获取项目路径

func ParseFileFormat

func ParseFileFormat(fileName string) string

ParseFileFormat 解析文件格式

Types

type FileHandle added in v1.0.2

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

FileHandle

func (*FileHandle) Close added in v1.0.2

func (fh *FileHandle) Close() error

Close 关闭文件句柄

func (*FileHandle) GetFile added in v1.0.2

func (fh *FileHandle) GetFile() *os.File

GetFile 获取文件操作句柄

type FilePool

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

FilePool 文件池

func NewFilePool

func NewFilePool(size int) *FilePool

NewFilePool 初始化文件池 默认会按 defaultExpireDur 进行淘汰 size 建议不用太大, 建议为待存放句柄的个数 1 倍好, 这样性能更加

func (*FilePool) Get

func (fp *FilePool) Get(path string, flag int, perm ...os.FileMode) (*FileHandle, error)

Get 获取文件句柄 注: 1. 调用完需要调用 Put 才能进行复用, 同时句柄不能"Close"

  1. 如果打算不用了的话, 必须调用 *FileHandle.Close 方法进行释放句柄, 防止内存泄露

func (*FilePool) Put

func (fp *FilePool) Put(fh *FileHandle, expire ...time.Time)

Put 归还

Jump to

Keyboard shortcuts

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