本站源代码
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.

40 lines
916B

  1. // Package vfsutil implements some I/O utility functions for http.FileSystem.
  2. package vfsutil
  3. import (
  4. "io/ioutil"
  5. "net/http"
  6. "os"
  7. )
  8. // ReadDir reads the contents of the directory associated with file and
  9. // returns a slice of FileInfo values in directory order.
  10. func ReadDir(fs http.FileSystem, name string) ([]os.FileInfo, error) {
  11. f, err := fs.Open(name)
  12. if err != nil {
  13. return nil, err
  14. }
  15. defer f.Close()
  16. return f.Readdir(0)
  17. }
  18. // Stat returns the FileInfo structure describing file.
  19. func Stat(fs http.FileSystem, name string) (os.FileInfo, error) {
  20. f, err := fs.Open(name)
  21. if err != nil {
  22. return nil, err
  23. }
  24. defer f.Close()
  25. return f.Stat()
  26. }
  27. // ReadFile reads the file named by path from fs and returns the contents.
  28. func ReadFile(fs http.FileSystem, path string) ([]byte, error) {
  29. rc, err := fs.Open(path)
  30. if err != nil {
  31. return nil, err
  32. }
  33. defer rc.Close()
  34. return ioutil.ReadAll(rc)
  35. }
上海开阖软件有限公司 沪ICP备12045867号-1