storage.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package storage
  2. import (
  3. "io"
  4. "os"
  5. "time"
  6. )
  7. // FileInfo represents information about a file
  8. type FileInfo interface {
  9. Name() string
  10. Size() int64
  11. Mode() os.FileMode
  12. ModTime() time.Time
  13. IsDir() bool
  14. }
  15. // FSOperator defines the interface for basic file system operations
  16. type FSOperator interface {
  17. // Read operations
  18. Read(path string) ([]byte, error)
  19. ReadStream(path string) (io.ReadCloser, error)
  20. // Write operations
  21. Write(path string, data []byte) error
  22. WriteStream(path string, data io.Reader) error
  23. // List operation
  24. List(path string) ([]FileInfo, error)
  25. // Get file info
  26. Stat(path string) (FileInfo, error)
  27. // Delete operation
  28. Delete(path string) error
  29. // Create directory
  30. Mkdir(path string, perm os.FileMode) error
  31. // Rename operation
  32. Rename(oldpath, newpath string) error
  33. // Check if file/directory exists
  34. Exists(path string) (bool, error)
  35. }
  36. // FullFSOperator extends FSOperator with additional operations
  37. type FullFSOperator interface {
  38. FSOperator
  39. // Copy operation
  40. Copy(src, dst string) error
  41. // Move operation
  42. Move(src, dst string) error
  43. // Recursive delete
  44. DeleteAll(path string) error
  45. // Create file
  46. Create(path string) (io.WriteCloser, error)
  47. // Open file with specific flag and permission
  48. OpenFile(path string, flag int, perm os.FileMode) (io.ReadWriteCloser, error)
  49. // Get file checksum
  50. Checksum(path string) (string, error)
  51. // Watch for file changes
  52. Watch(path string) (<-chan FileInfo, error)
  53. }