Package os - built-in os lib VFS implementation.
Rely on github.com/c2fo/vfs/v6/backend
import(
"github.com/c2fo/vfs/v6/backend"
"github.com/c2fo/vfs/v6/backend/os"
)
func UseFs() error {
fs := backend.Backend(os.Scheme)
...
}
Or call directly:
import _os "github.com/c2fo/vfs/v6/backend/os"
func DoSomething() {
fs := &_os.FileSystem{}
...
}
See: https://golang.org/pkg/os/
const Scheme = "file"
Scheme defines the file system type.
type File struct {
}
File implements vfs.File interface for S3 fs.
func (f *File) Close() error
Close implements the io.Closer interface, closing the underlying *os.File. its an error, if any.
func (f *File) CopyToFile(target vfs.File) error
CopyToFile copies the file to a new File. It accepts a vfs.File and returns an error, if any.
func (f *File) CopyToLocation(location vfs.Location) (vfs.File, error)
CopyToLocation copies existing File to new Location with the same name. It accepts a vfs.Location and returns a vfs.File and error, if any.
func (f *File) Delete() error
Delete unlinks the file returning any error or nil.
func (f *File) Exists() (bool, error)
Exists true if the file exists on the file system, otherwise false, and an error, if any.
func (f *File) LastModified() (*time.Time, error)
LastModified returns the timestamp of the file's mtime or error, if any.
func (f *File) Location() vfs.Location
Location returns the underlying os.Location.
func (f *File) MoveToFile(target vfs.File) error
MoveToFile move a file. It accepts a target vfs.File and returns an error, if any.
TODO: we might consider using os.Rename() for efficiency when target.Location().FileSystem().Scheme equals f.Location().FileSystem().Scheme()
func (f *File) MoveToLocation(location vfs.Location) (vfs.File, error)
MoveToLocation moves a file to a new Location. It accepts a target vfs.Location and returns a vfs.File and an error, if any.
TODO: we might consider using os.Rename() for efficiency when location.FileSystem().Scheme() equals f.Location().FileSystem().Scheme()
func (f *File) Name() string
Name returns the full name of the File relative to Location.Name().
func (f *File) Path() string
Path returns the path of the File relative to Location.Name().
func (f *File) Read(p []byte) (int, error)
Read implements the io.Reader interface. It returns the bytes read and an error, if any.
func (f *File) Seek(offset int64, whence int) (int64, error)
Seek implements the io.Seeker interface. It accepts an offset and "whence" where 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. It returns the new offset and an error, if any.
func (f *File) Size() (uint64, error)
Size returns the size (in bytes) of the File or any error.
func (f *File) String() string
String implement fmt.Stringer, returning the file's URI as the default string.
func (f *File) URI() string
URI returns the File's URI as a string.
func (f *File) Write(p []byte) (n int, err error)
Write implements the io.Writer interface. It accepts a slice of bytes and returns the number of bytes written and an error, if any.
type FileSystem struct{}
FileSystem implements vfs.FileSystem for the OS file system.
func (fs *FileSystem) Name() string
Name returns "os"
func (fs *FileSystem) NewFile(volume string, name string) (vfs.File, error)
NewFile function returns the os implementation of vfs.File.
func (fs *FileSystem) NewLocation(volume string, name string) (vfs.Location, error)
NewLocation function returns the os implementation of vfs.Location.
func (fs *FileSystem) Scheme() string
Scheme return "file" as the initial part of a file URI ie: file://
type Location struct {
}
Location implements the vfs.Location interface specific to OS fs.
func (l *Location) ChangeDir(relativePath string) error
ChangeDir takes a relative path, and modifies the underlying Location's path. The caller is modified by this so the only return is any error. For this implementation there are no errors.
func (l *Location) DeleteFile(fileName string) error
DeleteFile deletes the file of the given name at the location. This is meant to be a short cut for instantiating a new file and calling delete on that with all the necessary error handling overhead.
func (l *Location) Exists() (bool, error)
Exists returns true if the location exists, and the calling user has the appropriate permissions. Will receive false without an error if the location simply doesn't exist. Otherwise could receive false and any errors passed back from the OS.
func (l *Location) FileSystem() vfs.FileSystem
FileSystem returns a vfs.FileSystem interface of the location's underlying file system.
func (l *Location) List() ([]string, error)
List returns a slice of all files in the top directory of the location.
func (l *Location) ListByPrefix(prefix string) ([]string, error)
ListByPrefix returns a slice of all files starting with "prefix" in the top directory of the location.
func (l *Location) ListByRegex(regex *regexp.Regexp) ([]string, error)
ListByRegex returns a slice of all files matching the regex in the top directory of the location.
func (l *Location) NewFile(fileName string) (vfs.File, error)
NewFile uses the properties of the calling location to generate a vfs.File (backed by an os.File). A string argument is expected to be a relative path to the location's current path.
func (l *Location) NewLocation(relativePath string) (vfs.Location, error)
NewLocation makes a copy of the underlying Location, then modifies its path by calling ChangeDir with the relativePath argument, returning the resulting location. The only possible errors come from the call to ChangeDir.
func (l *Location) Path() string
Path returns the location path.
func (l *Location) String() string
String implement fmt.Stringer, returning the location's URI as the default string.
func (l *Location) URI() string
URI returns the Location's URI as a string.
func (l *Location) Volume() string
Volume returns the volume, if any, of the location. Given "C:\foo\bar" it returns "C:" on Windows. On other platforms it returns "".