github.com/sunvim/utils@v0.1.0/fs/fs.go (about)

     1  /*
     2  Package fs provides a file system interface.
     3  */
     4  package fs
     5  
     6  import (
     7  	"errors"
     8  	"io"
     9  	"os"
    10  )
    11  
    12  var (
    13  	errAppendModeNotSupported = errors.New("append mode is not supported")
    14  )
    15  
    16  // File is the interface compatible with os.File.
    17  type File interface {
    18  	io.Closer
    19  	io.Reader
    20  	io.ReaderAt
    21  	io.Seeker
    22  	io.Writer
    23  	io.WriterAt
    24  
    25  	// Stat returns os.FileInfo describing the file.
    26  	Stat() (os.FileInfo, error)
    27  
    28  	// Sync commits the current contents of the file.
    29  	Sync() error
    30  
    31  	// Truncate changes the size of the file.
    32  	Truncate(size int64) error
    33  
    34  	// Slice reads and returns the contents of file from offset start to offset end.
    35  	Slice(start int64, end int64) ([]byte, error)
    36  }
    37  
    38  // LockFile represents a lock file.
    39  type LockFile interface {
    40  	// Unlock and removes the lock file.
    41  	Unlock() error
    42  }
    43  
    44  // FileSystem represents a file system.
    45  type FileSystem interface {
    46  	// OpenFile opens the file with specified flag.
    47  	OpenFile(name string, flag int, perm os.FileMode) (File, error)
    48  
    49  	// Stat returns os.FileInfo describing the file.
    50  	Stat(name string) (os.FileInfo, error)
    51  
    52  	// Remove removes the file.
    53  	Remove(name string) error
    54  
    55  	// Rename renames oldpath to newpath.
    56  	Rename(oldpath, newpath string) error
    57  
    58  	// ReadDir reads the directory and returns a list of directory entries.
    59  	ReadDir(name string) ([]os.FileInfo, error)
    60  
    61  	// CreateLockFile creates a lock file.
    62  	CreateLockFile(name string, perm os.FileMode) (LockFile, bool, error)
    63  }