2019-10-29 07:35:16 +00:00
|
|
|
package backend
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2019-11-29 02:33:18 +00:00
|
|
|
_ BackendStorageFile = &DiskFile{}
|
2019-10-29 07:35:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type DiskFile struct {
|
|
|
|
File *os.File
|
|
|
|
fullFilePath string
|
|
|
|
}
|
|
|
|
|
2019-10-30 05:37:36 +00:00
|
|
|
func NewDiskFile(f *os.File) *DiskFile {
|
2019-10-29 07:35:16 +00:00
|
|
|
return &DiskFile{
|
2019-10-30 05:37:36 +00:00
|
|
|
fullFilePath: f.Name(),
|
2019-10-29 07:35:16 +00:00
|
|
|
File: f,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *DiskFile) ReadAt(p []byte, off int64) (n int, err error) {
|
|
|
|
return df.File.ReadAt(p, off)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) {
|
|
|
|
return df.File.WriteAt(p, off)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *DiskFile) Truncate(off int64) error {
|
|
|
|
return df.File.Truncate(off)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *DiskFile) Close() error {
|
|
|
|
return df.File.Close()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (df *DiskFile) GetStat() (datSize int64, modTime time.Time, err error) {
|
|
|
|
stat, e := df.File.Stat()
|
|
|
|
if e == nil {
|
|
|
|
return stat.Size(), stat.ModTime(), nil
|
|
|
|
}
|
|
|
|
return 0, time.Time{}, err
|
|
|
|
}
|
|
|
|
|
2019-12-09 03:44:16 +00:00
|
|
|
func (df *DiskFile) Name() string {
|
2019-10-29 07:35:16 +00:00
|
|
|
return df.fullFilePath
|
|
|
|
}
|
2020-03-20 06:54:52 +00:00
|
|
|
|
|
|
|
func (df *DiskFile) Sync() error {
|
|
|
|
return df.File.Sync()
|
|
|
|
}
|