代码拉取完成,页面将自动刷新
package gfpool
import (
"errors"
"fmt"
"os"
"time"
)
// 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 Open(path string, flag int, perm os.FileMode, ttl ...time.Duration) (file *File, err error) {
var fpTTL time.Duration
if len(ttl) > 0 {
fpTTL = ttl[0]
}
// DO NOT search the path here wasting performance!
// Leave following codes just for warning you.
//
//path, err = gfile.Search(path)
//if err != nil {
// return nil, err
//}
pool := pools.GetOrSetFuncLock(
fmt.Sprintf("%s&%d&%d&%d", path, flag, fpTTL, perm),
func() interface{} {
return New(path, flag, perm, fpTTL)
},
).(*Pool)
return pool.File()
}
// Stat returns the FileInfo structure describing file.
func (f *File) Stat() (os.FileInfo, error) {
if f.stat == nil {
return nil, errors.New("file stat is empty")
}
return f.stat, nil
}
// Close puts the file pointer back to the file pointer pool.
func (f *File) Close() error {
if f.pid == f.pool.id.Val() {
return f.pool.pool.Put(f)
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。