Documentation ¶
Overview ¶
Package mem built-in mem lib VFS implementation. Usage Rely on github.com/c2fo/vfs/v6/backend
import( "github.com/c2fo/vfs/v6/backend" "github.com/c2fo/vfs/v6/backend/mem" ) func UseFs() error { fs := backend.Backend(mem.Scheme) ... }
Or call directly:
import _mem "github.com/c2fo/vfs/v6/backend/mem" func DoSomething() { fs := _mem.NewFileSystem() ... }
Index ¶
- Constants
- type File
- func (f *File) Close() error
- func (f *File) CopyToFile(target vfs.File) error
- func (f *File) CopyToLocation(location vfs.Location) (vfs.File, error)
- func (f *File) Delete(_ ...options.DeleteOption) error
- func (f *File) Exists() (bool, error)
- func (f *File) LastModified() (*time.Time, error)
- func (f *File) Location() vfs.Location
- func (f *File) MoveToFile(file vfs.File) error
- func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error)
- func (f *File) Name() string
- func (f *File) Path() string
- func (f *File) Read(p []byte) (n int, err error)
- func (f *File) Seek(offset int64, whence int) (int64, error)
- func (f *File) Size() (uint64, error)
- func (f *File) String() string
- func (f *File) Touch() error
- func (f *File) URI() string
- func (f *File) Write(p []byte) (int, error)
- type FileSystem
- type Location
- func (l *Location) ChangeDir(relLocPath string) error
- func (l *Location) DeleteFile(relFilePath string, _ ...options.DeleteOption) error
- func (l *Location) Exists() (bool, error)
- func (l *Location) FileSystem() vfs.FileSystem
- func (l *Location) List() ([]string, error)
- func (l *Location) ListByPrefix(prefix string) ([]string, error)
- func (l *Location) ListByRegex(regex *regexp.Regexp) ([]string, error)
- func (l *Location) NewFile(relFilePath string) (vfs.File, error)
- func (l *Location) NewLocation(relLocPath string) (vfs.Location, error)
- func (l *Location) Path() string
- func (l *Location) String() string
- func (l *Location) URI() string
- func (l *Location) Volume() string
Constants ¶
const Scheme = "mem"
Scheme defines the FileSystem type's underlying implementation.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type File ¶
type File struct {
// contains filtered or unexported fields
}
File implements vfs.File interface for the in-memory implementation of FileSystem. A file struct holds a pointer to a single memFile. Multiple threads will refer to the same memFile. Simultaneous reading is allowed, but writing and closing are protected by locks.
func (*File) CopyToFile ¶
CopyToFile copies the receiver file into the target file. Additionally, after this is called, f's cursor will reset as if it had been closed.
func (*File) CopyToLocation ¶
CopyToLocation copies the current file to the given location. If file exists at given location contents are simply overwritten using "CopyToFile", otherwise a newFile is made, takes the contents of the current file, and ends up at the given location
func (*File) Delete ¶
func (f *File) Delete(_ ...options.DeleteOption) error
Delete removes the file from the FileSystem. Sets it path in the fsMap to nil, and also nils the file's members
func (*File) Exists ¶
Exists returns whether or not a file exists. Creating a file does not guarantee its existence, but creating one and writing to it does
func (*File) LastModified ¶
LastModified simply returns the file's lastModified, if the file exists
func (*File) Location ¶
func (f *File) Location() vfs.Location
Location simply returns the file's underlying location struct pointer
func (*File) MoveToFile ¶
MoveToFile creates a newFile, and moves it to "file". The receiver is always deleted (since it's being "moved")
func (*File) MoveToLocation ¶
MoveToLocation moves the receiver file to the passed in location. It does so by creating a copy of 'f' in "location". 'f' is subsequently deleted
func (*File) Read ¶
Read implements the io.Reader interface. Returns number of bytes read and potential errors
func (*File) Seek ¶
Seek implements the io.Seeker interface. Returns the current position of the cursor and errors if any
func (*File) Size ¶
Size returns the size of the file contents. In our case, the length of the file's byte slice
func (*File) String ¶
String implements the io.Stringer interface. It returns a string representation of the file's URI
type FileSystem ¶
type FileSystem struct {
// contains filtered or unexported fields
}
FileSystem implements vfs.FileSystem for an in-memory file system.
func NewFileSystem ¶
func NewFileSystem() *FileSystem
NewFileSystem is used to initialize the file system struct for an in-memory FileSystem.
func (*FileSystem) Name ¶
func (fs *FileSystem) Name() string
Name returns the name of the underlying FileSystem
func (*FileSystem) NewFile ¶
func (fs *FileSystem) NewFile(volume, absFilePath string) (vfs.File, error)
NewFile function returns the in-memory implementation of vfs.File. Since this is inside FileSystem, we assume that the caller knows that the CWD is the root. If a non-absolute path is given, an error is thrown. Additionally, a file does not technically exist until a call to "Touch()" is made on it. The "Touch" call links the file with FileSystem's map and brings it into existence. If a file is written to before a touch call, Write() will take care of that call. This is true for other functions as well and existence only poses a problem in the context of deletion or copying FROM a non-existent file.
func (*FileSystem) NewLocation ¶
func (fs *FileSystem) NewLocation(volume, absLocPath string) (vfs.Location, error)
NewLocation function returns the in-memory implementation of vfs.Location. A location always exists. If a file is created on a location that has not yet been made in the fsMap, then the location will be created with the file
func (*FileSystem) Retry ¶
func (fs *FileSystem) Retry() vfs.Retry
Retry will return a retrier provided via options, or a no-op if none is provided.
func (*FileSystem) Scheme ¶
func (fs *FileSystem) Scheme() string
Scheme returns the scheme of the underlying FileSystem
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location implements the vfs.Location interface specific to in-memory FileSystem.
func (*Location) DeleteFile ¶
func (l *Location) DeleteFile(relFilePath string, _ ...options.DeleteOption) error
DeleteFile locates the file given the fileName and calls delete on it
func (*Location) FileSystem ¶
func (l *Location) FileSystem() vfs.FileSystem
FileSystem returns the type of file system location exists on, if it exists at all
func (*Location) List ¶
List finds all of the files living at the current location and returns them in a slice of strings. If there are no files at location, then an empty slice will be returned
func (*Location) ListByPrefix ¶
ListByPrefix tags a prefix onto the current path and in a slice, returns all file base names whose full paths contain that substring Returns empty slice if nothing found
func (*Location) ListByRegex ¶
ListByRegex takes a regular expression and returns a slice of strings containing the base names of files found that matched the regular expression. Returns an empty slice upon nothing found
func (*Location) NewFile ¶
NewFile creates a vfs.File given its relative path and tags it onto "l's" path
func (*Location) NewLocation ¶
NewLocation creates a new location at the given relative path, which is tagged onto the current locations absolute path
func (*Location) Path ¶
Path returns the full, absolute path of the location with leading and trailing slashes