github.com/gocaveman/caveman@v0.0.0-20191211162744-0ddf99dbdf6e/filesystem/filesystem.go (about)

     1  // The filesystem package provides an interface for a filesystem using only stdlib types.
     2  // The filesystem.FileSystem interface was inspired by github.com/spf13/afero but addresses
     3  // the issue that implementations of afero must depend on the afero library (due to the fact that
     4  // some methods return afero.File - we instead return anonymous interfaces that just list
     5  // the required methods for the return type).  Well-designed interfaces should
     6  // reduce coupling rather than add it.  Thus this interface can be implemented by other packages
     7  // with no regard as to whether they are intended for use with Caveman or not and yet be
     8  // interoperable.  Some of unnecessary/redundant methods (Stat, Truncate, WriteString) have been removed in order to simplify.
     9  // Also some methods (Sync, Name, ReadAt, WriteAt) did not seem relevant enough to enforce at the interface level,
    10  // however the underlying implementation may still provide it, in which case it and it can be accessed
    11  // with a type assertion.
    12  // The subdir "aferofs" provides an implementation that adapts an afero.Fs to
    13  // implement filesystem.Filesystem.
    14  package filesystem
    15  
    16  import (
    17  	"os"
    18  	"time"
    19  )
    20  
    21  // FileSystem should be implemented to provide a working read/write filesystem.
    22  // These methods should the same as described in the os package.
    23  type FileSystem interface {
    24  	Chmod(name string, mode os.FileMode) error
    25  	Chtimes(name string, atime time.Time, mtime time.Time) error
    26  	Mkdir(name string, perm os.FileMode) error
    27  	MkdirAll(path string, perm os.FileMode) error
    28  
    29  	Remove(name string) error
    30  	RemoveAll(path string) error
    31  	Rename(oldname, newname string) error
    32  	Stat(name string) (os.FileInfo, error)
    33  
    34  	Create(name string) (interface {
    35  		Close() error
    36  		Seek(offset int64, whence int) (int64, error)
    37  		Read(p []byte) (n int, err error)
    38  		Write(data []byte) (n int, err error)
    39  	}, error)
    40  	OpenFile(name string, flag int, perm os.FileMode) (interface {
    41  		Close() error
    42  		Seek(offset int64, whence int) (int64, error)
    43  		Read(p []byte) (n int, err error)
    44  		Write(data []byte) (n int, err error)
    45  		Readdir(count int) ([]os.FileInfo, error)
    46  		Readdirnames(n int) ([]string, error)
    47  	}, error)
    48  	Open(name string) (interface {
    49  		Close() error
    50  		Seek(offset int64, whence int) (int64, error)
    51  		Read(p []byte) (n int, err error)
    52  		Readdir(count int) ([]os.FileInfo, error)
    53  		Readdirnames(n int) ([]string, error)
    54  	}, error)
    55  }