gfpool

package
v1.15.3 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 8 Imported by: 4

Documentation

Overview

Package gfpool provides io-reusable pool for file pointer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	*os.File // Underlying file pointer.
	// contains filtered or unexported fields
}

File is an item in the pool.

func Open

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

Open creates and returns a file item with given file path, flag and opening permission. It automatically creates an associated file pointer pool internally when it's called first time. It retrieves a file item from the file pointer pool after then.

func (*File) Close

func (f *File) Close() error

Close puts the file pointer back to the file pointer pool.

func (*File) Stat added in v1.11.7

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

Stat returns the FileInfo structure describing file.

type Pool

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

File pointer pool.

func New

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

New creates and returns a file pointer pool with given file path, flag and opening permission.

Note the expiration logic: ttl = 0 : not expired; ttl < 0 : immediate expired after use; ttl > 0 : timeout expired; It is not expired in default.

func (*Pool) Close

func (p *Pool) Close()

Close closes current file pointer pool.

func (*Pool) File

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

File retrieves file item from the file pointer pool and returns it. It creates one if the file pointer pool is empty. Note that it should be closed when it will never be used. When it's closed, it is not really closed the underlying file pointer but put back to the file pinter pool.

Jump to

Keyboard shortcuts

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