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

109 lines
3.2KB

  1. // Copyright © 2014 Steve Francia <spf@spf13.com>.
  2. // Copyright 2013 tsuru authors. All rights reserved.
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // Package afero provides types and methods for interacting with the filesystem,
  15. // as an abstraction layer.
  16. // Afero also provides a few implementations that are mostly interoperable. One that
  17. // uses the operating system filesystem, one that uses memory to store files
  18. // (cross platform) and an interface that should be implemented if you want to
  19. // provide your own filesystem.
  20. package afero
  21. import (
  22. "errors"
  23. "io"
  24. "os"
  25. "time"
  26. )
  27. type Afero struct {
  28. Fs
  29. }
  30. // File represents a file in the filesystem.
  31. type File interface {
  32. io.Closer
  33. io.Reader
  34. io.ReaderAt
  35. io.Seeker
  36. io.Writer
  37. io.WriterAt
  38. Name() string
  39. Readdir(count int) ([]os.FileInfo, error)
  40. Readdirnames(n int) ([]string, error)
  41. Stat() (os.FileInfo, error)
  42. Sync() error
  43. Truncate(size int64) error
  44. WriteString(s string) (ret int, err error)
  45. }
  46. // Fs is the filesystem interface.
  47. //
  48. // Any simulated or real filesystem should implement this interface.
  49. type Fs interface {
  50. // Create creates a file in the filesystem, returning the file and an
  51. // error, if any happens.
  52. Create(name string) (File, error)
  53. // Mkdir creates a directory in the filesystem, return an error if any
  54. // happens.
  55. Mkdir(name string, perm os.FileMode) error
  56. // MkdirAll creates a directory path and all parents that does not exist
  57. // yet.
  58. MkdirAll(path string, perm os.FileMode) error
  59. // Open opens a file, returning it or an error, if any happens.
  60. Open(name string) (File, error)
  61. // OpenFile opens a file using the given flags and the given mode.
  62. OpenFile(name string, flag int, perm os.FileMode) (File, error)
  63. // Remove removes a file identified by name, returning an error, if any
  64. // happens.
  65. Remove(name string) error
  66. // RemoveAll removes a directory path and any children it contains. It
  67. // does not fail if the path does not exist (return nil).
  68. RemoveAll(path string) error
  69. // Rename renames a file.
  70. Rename(oldname, newname string) error
  71. // Stat returns a FileInfo describing the named file, or an error, if any
  72. // happens.
  73. Stat(name string) (os.FileInfo, error)
  74. // The name of this FileSystem
  75. Name() string
  76. //Chmod changes the mode of the named file to mode.
  77. Chmod(name string, mode os.FileMode) error
  78. //Chtimes changes the access and modification times of the named file
  79. Chtimes(name string, atime time.Time, mtime time.Time) error
  80. }
  81. var (
  82. ErrFileClosed = errors.New("File is closed")
  83. ErrOutOfRange = errors.New("Out of range")
  84. ErrTooLarge = errors.New("Too large")
  85. ErrFileNotFound = os.ErrNotExist
  86. ErrFileExists = os.ErrExist
  87. ErrDestinationExists = os.ErrExist
  88. )
上海开阖软件有限公司 沪ICP备12045867号-1