Documentation ¶
Overview ¶
Package filesys provides a standard definition of a filesys which can be implemented to abstract away the differences between a local filesystem, cloud storage, in memory data etc.
Index ¶
- Variables
- func UnmarshalJSONFile(fs ReadableFS, path string, dest interface{}) error
- type FSIterCB
- type Filesys
- type FilesysLock
- type InMemFS
- func (fs *InMemFS) Abs(path string) (string, error)
- func (fs *InMemFS) Delete(path string, force bool) error
- func (fs *InMemFS) DeleteFile(path string) error
- func (fs *InMemFS) Exists(path string) (exists bool, isDir bool)
- func (fs *InMemFS) Iter(path string, recursive bool, cb FSIterCB) error
- func (fs *InMemFS) LastModified(path string) (t time.Time, exists bool)
- func (fs *InMemFS) MkDirs(path string) error
- func (fs *InMemFS) MoveFile(srcPath, destPath string) error
- func (fs *InMemFS) OpenForRead(fp string) (io.ReadCloser, error)
- func (fs *InMemFS) OpenForWrite(fp string, perm os.FileMode) (io.WriteCloser, error)
- func (fs *InMemFS) OpenForWriteAppend(fp string, perm os.FileMode) (io.WriteCloser, error)
- func (fs *InMemFS) ReadFile(fp string) ([]byte, error)
- func (fs InMemFS) WithWorkingDir(path string) (Filesys, error)
- func (fs *InMemFS) WriteFile(fp string, data []byte) error
- type InMemFileLock
- type LocalFileLock
- type ReadWriteFS
- type ReadableFS
- type WalkableFS
- type WritableFS
Constants ¶
This section is empty.
Variables ¶
var ErrDirNotExist = errors.New("directory does not exist")
var ErrIsDir = errors.New("operation not valid on a directory")
var ErrIsFile = errors.New("operation not valid on a file")
var InMemNowFunc = time.Now
InMemNowFunc is a func() time.Time that can be used to supply the current time. The default value gets the current time from the system clock, but it can be set to something else in order to support reproducible tests.
var LocalFS = &localFS{}
LocalFS is the machines local filesystem
Functions ¶
func UnmarshalJSONFile ¶
func UnmarshalJSONFile(fs ReadableFS, path string, dest interface{}) error
Types ¶
type FSIterCB ¶
FSIterCB specifies the signature of the function that will be called for every item found while iterating.
type Filesys ¶
type Filesys interface { ReadableFS WritableFS WalkableFS // WithWorkingDir returns a copy of this Filesys with the given working directory WithWorkingDir(path string) (Filesys, error) }
Filesys is an interface whose implementors will provide read, write, and list mechanisms
func LocalFilesysWithWorkingDir ¶
LocalFilesysWithWorkingDir returns a new Filesys implementation backed by the local filesystem with the supplied working directory. Path relative operations occur relative to this directory.
type FilesysLock ¶
FilesysLock is an interface for locking and unlocking filesystems
func CreateFilesysLock ¶
func CreateFilesysLock(fs Filesys, filename string) FilesysLock
CreateFilesysLock creates a new FilesysLock
type InMemFS ¶
type InMemFS struct {
// contains filtered or unexported fields
}
InMemFS is an in memory filesystem implementation that is primarily intended for testing
func EmptyInMemFS ¶
EmptyInMemFS creates an empty InMemFS instance
func NewInMemFS ¶
NewInMemFS creates an InMemFS with directories and folders provided.
func (*InMemFS) Abs ¶
converts a path to an absolute path. If it's already an absolute path the input path will be returned unaltered
func (*InMemFS) Delete ¶
Delete will delete an empty directory, or a file. If trying delete a directory that is not empty you can set force to true in order to delete the dir and all of it's contents
func (*InMemFS) DeleteFile ¶
DeleteFile will delete a file at the given path
func (*InMemFS) Exists ¶
Exists will tell you if a file or directory with a given path already exists, and if it does is it a directory
func (*InMemFS) Iter ¶
Iter iterates over the files and subdirectories within a given directory (Optionally recursively). There are no guarantees about the ordering of results. It is also possible that concurrent delete operations could render a file path invalid when the callback is made.
func (*InMemFS) LastModified ¶
LastModified gets the last modified timestamp for a file or directory at a given path
func (*InMemFS) MkDirs ¶
MkDirs creates a folder and all the parent folders that are necessary to create it.
func (*InMemFS) MoveFile ¶
MoveFile will move a file from the srcPath in the filesystem to the destPath
func (*InMemFS) OpenForRead ¶
func (fs *InMemFS) OpenForRead(fp string) (io.ReadCloser, error)
OpenForRead opens a file for reading
func (*InMemFS) OpenForWrite ¶
OpenForWrite opens a file for writing. The file will be created if it does not exist, and if it does exist it will be overwritten.
func (*InMemFS) OpenForWriteAppend ¶
OpenForWriteAppend opens a file for writing. The file will be created if it does not exist, and if it does exist it will append to existing file.
func (InMemFS) WithWorkingDir ¶
WithWorkingDir returns a copy of this file system with the current working dir set to the path given
type InMemFileLock ¶
type InMemFileLock struct {
// contains filtered or unexported fields
}
InMemFileLock is a lock for the InMemFS
func NewInMemFileLock ¶
func NewInMemFileLock(fs Filesys) *InMemFileLock
NewInMemFileLock creates a new InMemFileLock
func (*InMemFileLock) TryLock ¶
func (memLock *InMemFileLock) TryLock() (bool, error)
TryLock attempts to lock the lock or fails if it is already locked
type LocalFileLock ¶
type LocalFileLock struct {
// contains filtered or unexported fields
}
LocalFileLock is the lock for the localFS
func NewLocalFileLock ¶
func NewLocalFileLock(fs Filesys, filename string) *LocalFileLock
NewLocalFileLock creates a new LocalFileLock
func (*LocalFileLock) TryLock ¶
func (locLock *LocalFileLock) TryLock() (bool, error)
TryLock attempts to lock the lock or fails if it is already locked
type ReadWriteFS ¶
type ReadWriteFS interface { ReadableFS WritableFS }
ReadWriteFS is an interface whose implementors will provide read, and write implementations but may not allow for files to be listed.
type ReadableFS ¶
type ReadableFS interface { // OpenForRead opens a file for reading OpenForRead(fp string) (io.ReadCloser, error) // ReadFile reads the entire contents of a file ReadFile(fp string) ([]byte, error) // Exists will tell you if a file or directory with a given path already exists, and if it does is it a directory Exists(path string) (exists bool, isDir bool) // converts a path to an absolute path. If it's already an absolute path the input path will be returned unaltered Abs(path string) (string, error) // LastModified gets the last modified timestamp for a file or directory at a given path LastModified(path string) (t time.Time, exists bool) }
ReadableFS is an interface providing read access to objs in a filesystem
type WalkableFS ¶
type WalkableFS interface { // Iter iterates over the files and subdirectories within a given directory (Optionally recursively). There // are no guarantees about the ordering of results. Two calls to iterate the same directory may yield // differently ordered results. Iter(directory string, recursive bool, cb FSIterCB) error }
WalkableFS is an interface for walking the files and subdirectories of a directory
type WritableFS ¶
type WritableFS interface { // OpenForWrite opens a file for writing. The file will be created if it does not exist, and if it does exist // it will be overwritten. OpenForWrite(fp string, perm os.FileMode) (io.WriteCloser, error) // OpenForWriteAppend opens a file for writing. The file will be created if it does not exist, and it will // append only to that new file. If file exists, it will append to existing file. OpenForWriteAppend(fp string, perm os.FileMode) (io.WriteCloser, error) // WriteFile writes the entire data buffer to a given file. The file will be created if it does not exist, // and if it does exist it will be overwritten. WriteFile(fp string, data []byte) error // MkDirs creates a folder and all the parent folders that are necessary to create it. MkDirs(path string) error // DeleteFile will delete a file at the given path DeleteFile(path string) error // Delete will delete an empty directory, or a file. If trying delete a directory that is not empty you can set force to // true in order to delete the dir and all of it's contents Delete(path string, force bool) error // MoveFile will move a file from the srcPath in the filesystem to the destPath MoveFile(srcPath, destPath string) error }
WritableFS is an interface providing write access to objs in a filesystem