filesystem.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package fs
  2. import (
  3. "io/ioutil"
  4. "os"
  5. "path/filepath"
  6. )
  7. // FileSystem defines the methods of an abstract filesystem.
  8. type FileSystem interface {
  9. // ReadDir reads the directory named by dirname and returns a
  10. // list of directory entries.
  11. ReadDir(dirname string) ([]os.FileInfo, error)
  12. // Lstat returns a FileInfo describing the named file. If the file is a
  13. // symbolic link, the returned FileInfo describes the symbolic link. Lstat
  14. // makes no attempt to follow the link.
  15. Lstat(name string) (os.FileInfo, error)
  16. // Join joins any number of path elements into a single path, adding a
  17. // separator if necessary. The result is Cleaned; in particular, all
  18. // empty strings are ignored.
  19. //
  20. // The separator is FileSystem specific.
  21. Join(elem ...string) string
  22. }
  23. // fs represents a FileSystem provided by the os package.
  24. type fs struct{}
  25. func (f *fs) ReadDir(dirname string) ([]os.FileInfo, error) { return ioutil.ReadDir(dirname) }
  26. func (f *fs) Lstat(name string) (os.FileInfo, error) { return os.Lstat(name) }
  27. func (f *fs) Join(elem ...string) string { return filepath.Join(elem...) }