Documentation ¶
Index ¶
- func ReadDir(ctx context.Context, fs FS, path string) (rv []fs.FileInfo, rvErr error)
- func ReadFile(ctx context.Context, fs FS, path string) (rv []byte, rvErr error)
- func Stat(ctx context.Context, fs FS, path string) (rv fs.FileInfo, rvErr error)
- func Walk(ctx context.Context, fs FS, root string, walkFn filepath.WalkFunc) error
- func WriteFile(ctx context.Context, fs FS, path string, data []byte) error
- type FS
- type File
- type FileInfo
- type FileInfoImpl
- type ReuseContextFile
- type TempDirFS
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FS ¶
type FS interface { // Open the given path for reading only. If the path is a directory, // implementations should return a ReadDirFile. Open(ctx context.Context, name string) (File, error) // Create creates or truncates the named file. If the file already exists, // it is truncated. If the file does not exist, it is created with mode 0666 // (before umask). If successful, methods on the returned File can be used // for I/O; the associated file descriptor has mode O_RDWR. If there is an // error, it will be of type *PathError. Create(ctx context.Context, name string) (File, error) // Close causes any resources associated with the FS to be cleaned up. Close(ctx context.Context) error }
FS represents a virtual filesystem.
func InRepoRoot ¶
InRepoRoot returns a FS which uses the local filesystem with the root being the root of the Git repository where the current working directory resides. Absolute paths may only be passed to Open() if they are subdirectories of the given root. Relative paths must not contain ".."
type File ¶
type File interface { // Close the File. Close(ctx context.Context) error // Read behaves like io.Reader. It should return an error if this is a // directory. Read(ctx context.Context, buf []byte) (int, error) // Stat returns FileInfo associated with the File. Stat(ctx context.Context) (fs.FileInfo, error) // ReadDir returns the contents of the File if it is a directory, and // returns an error otherwise. Should behave the same as os.File.Readdir. ReadDir(ctx context.Context, n int) ([]fs.FileInfo, error) // Write is analogous to os.File.Write(). It writes the contents of b to the // File and returns the number of bytes written and an error, if any. Write // returns a non-nil error when n != len(b). Only valid if the File was // created using FS.Create. Write(ctx context.Context, b []byte) (n int, err error) }
File represents a virtual file.
type FileInfo ¶
type FileInfo struct { Name string Size int64 Mode os.FileMode ModTime time.Time IsDir bool Sys interface{} }
FileInfo implements fs.FileInfo by simply filling out the return values for all of the methods.
func (FileInfo) Get ¶
func (fi FileInfo) Get() *FileInfoImpl
Get returns an fs.FileInfo backed by this FileInfo.
type FileInfoImpl ¶
type FileInfoImpl struct {
FileInfo
}
FileInfoImpl implements fs.FileInfo.
func (*FileInfoImpl) ModTime ¶
func (fi *FileInfoImpl) ModTime() time.Time
ModTime implements fs.FileInfo.
type ReuseContextFile ¶
type ReuseContextFile struct { File // contains filtered or unexported fields }
ReuseContextFile is a File which reuses the same Context for all calls. This is useful for passing the File into library functions which do not use Contexts.
func WithContext ¶
func WithContext(ctx context.Context, f File) *ReuseContextFile
WithContext returns a ReuseContextFile which wraps the given File.
func (*ReuseContextFile) Close ¶
func (f *ReuseContextFile) Close() error
Close closes the ReuseContextFile.
type TempDirFS ¶
type TempDirFS struct { FS // contains filtered or unexported fields }
TempDirFS is a FS implementation which is rooted in a temporary directory. Calling Close causes the directory to be deleted.
func TempDir ¶
TempDir returns a FS which is rooted in a temporary directory. Calling Close causes the directory to be deleted.