文件指针池类

package
v0.0.0-...-2910145 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package gfpool 提供了用于文件指针的可重用 io 资源池。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	*os.File // 底层文件指针。
	// contains filtered or unexported fields
}

File 是池中的一个项目。

func Get

func Get(path string, flag int, perm os.FileMode, ttl ...time.Duration) (file *File)

Get 函数通过给定的文件路径、标志和打开权限获取一个文件项。 然后,它从文件指针池中检索一个文件项。

func Open

func Open(path string, flag int, perm os.FileMode, ttl ...time.Duration) (file *File, err error)

Open 函数通过给定的文件路径、标志和打开权限创建并返回一个文件项。 当首次调用时,它会自动内部创建一个相关的文件指针池。 此后,它将从该文件指针池中获取文件项。

func (*File) Close

func (f *File) Close(close ...bool) error

Close将文件指针放回文件指针池。

func (*File) Stat

func (f *File) Stat() (os.FileInfo, error)

Stat返回描述文件的FileInfo结构体。

type Pool

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

Pool 指针池。

func New

func New(path string, flag int, perm os.FileMode, ttl ...time.Duration) *Pool

New根据给定的文件路径、标志和打开权限创建并返回一个文件指针池。

注意过期逻辑: ttl = 0 : 不过期; ttl < 0 : 使用后立即过期; ttl > 0 : 超时后过期; 默认情况下,它不会过期。

func (*Pool) Close

func (p *Pool) Close()

Close 关闭当前文件指针池。

func (*Pool) File

func (p *Pool) File() (*File, error)

File 从文件指针池中获取文件项并返回,如果文件指针池为空,则创建一个新的文件项。 注意:当文件项不再使用时,应关闭它。当其被关闭时,并非真正关闭底层的文件指针,而是将其放回文件指针池中。

Jump to

Keyboard shortcuts

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