stat_windows.go 988 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package system
  2. import (
  3. "os"
  4. "time"
  5. )
  6. // StatT type contains status of a file. It contains metadata
  7. // like permission, size, etc about a file.
  8. type StatT struct {
  9. mode os.FileMode
  10. size int64
  11. mtim time.Time
  12. }
  13. // Size returns file's size.
  14. func (s StatT) Size() int64 {
  15. return s.size
  16. }
  17. // Mode returns file's permission mode.
  18. func (s StatT) Mode() os.FileMode {
  19. return os.FileMode(s.mode)
  20. }
  21. // Mtim returns file's last modification time.
  22. func (s StatT) Mtim() time.Time {
  23. return time.Time(s.mtim)
  24. }
  25. // Stat takes a path to a file and returns
  26. // a system.StatT type pertaining to that file.
  27. //
  28. // Throws an error if the file does not exist
  29. func Stat(path string) (*StatT, error) {
  30. fi, err := os.Stat(path)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return fromStatT(&fi)
  35. }
  36. // fromStatT converts a os.FileInfo type to a system.StatT type
  37. func fromStatT(fi *os.FileInfo) (*StatT, error) {
  38. return &StatT{
  39. size: (*fi).Size(),
  40. mode: (*fi).Mode(),
  41. mtim: (*fi).ModTime()}, nil
  42. }