You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
940 B

5 years ago
  1. package backend
  2. import (
  3. "os"
  4. "time"
  5. )
  6. var (
  7. _ BackendStorageFile = &DiskFile{}
  8. )
  9. type DiskFile struct {
  10. File *os.File
  11. fullFilePath string
  12. }
  13. func NewDiskFile(f *os.File) *DiskFile {
  14. return &DiskFile{
  15. fullFilePath: f.Name(),
  16. File: f,
  17. }
  18. }
  19. func (df *DiskFile) ReadAt(p []byte, off int64) (n int, err error) {
  20. return df.File.ReadAt(p, off)
  21. }
  22. func (df *DiskFile) WriteAt(p []byte, off int64) (n int, err error) {
  23. return df.File.WriteAt(p, off)
  24. }
  25. func (df *DiskFile) Truncate(off int64) error {
  26. return df.File.Truncate(off)
  27. }
  28. func (df *DiskFile) Close() error {
  29. return df.File.Close()
  30. }
  31. func (df *DiskFile) GetStat() (datSize int64, modTime time.Time, err error) {
  32. stat, e := df.File.Stat()
  33. if e == nil {
  34. return stat.Size(), stat.ModTime(), nil
  35. }
  36. return 0, time.Time{}, err
  37. }
  38. func (df *DiskFile) Name() string {
  39. return df.fullFilePath
  40. }
  41. func (df *DiskFile) Sync() error {
  42. return df.File.Sync()
  43. }