Documentation ¶
Overview ¶
Package os built-in os lib VFS implementation.
Usage ¶
Rely on github.com/c2fo/vfs/backend
import( "github.com/c2fo/vfs/backend" "github.com/c2fo/vfs/backend/os" ) func UseFs() error { fs, err := backend.Backend(os.Scheme) ... }
Or call directly:
import _os "github.com/c2fo/vfs/backend/os" func DoSomething() { fs := &_os.FileSystem{} ... }
See Also ¶
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() error
- func (f *File) Exists() (bool, error)
- func (f *File) LastModified() (*time.Time, error)
- func (f *File) Location() vfs.Location
- func (f *File) MoveToFile(target 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) (int, 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) URI() string
- func (f *File) Write(p []byte) (n int, err error)
- type FileSystem
- type Location
- func (l *Location) ChangeDir(relativePath string) error
- func (l *Location) DeleteFile(fileName string) 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(fileName string) (vfs.File, error)
- func (l *Location) NewLocation(relativePath 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 = "file"
Scheme defines the filesystem type.
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 os fs.
func (*File) Close ¶
Close implements the io.Closer interface, closing the underlying *os.File. its an error, if any.
func (*File) CopyToFile ¶
CopyToFile copies the file to a new File. It accepts a vfs.File and returns an error, if any.
func (*File) CopyToLocation ¶
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 (*File) Exists ¶
Exists true if the file exists on the filesystem, otherwise false, and an error, if any.
func (*File) LastModified ¶
LastModified returns the timestamp of the file's mtime or error, if any.
func (*File) MoveToFile ¶
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 (*File) MoveToLocation ¶
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 (*File) Read ¶
Read implements the io.Reader interface. It returns the bytes read and an error, if any.
func (*File) Seek ¶
Seek implements the io.Seeker interface. It accepts an offset and "whench" 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.
type FileSystem ¶
type FileSystem struct{}
FileSystem implements vfs.Filesystem for the OS filesystem.
func (*FileSystem) NewLocation ¶
NewLocation function returns the os implementation of vfs.Location.
func (*FileSystem) Scheme ¶
func (fs *FileSystem) Scheme() string
Scheme return "file" as the initial part of a file URI ie: file://
type Location ¶
type Location struct {
// contains filtered or unexported fields
}
Location implements the vfs.Location interface specific to OS fs.
func (*Location) ChangeDir ¶
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 (*Location) DeleteFile ¶
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 (*Location) Exists ¶
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 (*Location) FileSystem ¶
func (l *Location) FileSystem() vfs.FileSystem
FileSystem returns a vfs.FileSystem interface of the location's underlying fileSystem.
func (*Location) ListByPrefix ¶
ListByPrefix returns a slice of all files starting with "prefix" in the top directory of of the location.
func (*Location) ListByRegex ¶
ListByRegex returns a slice of all files matching the regex in the top directory of of the location.
func (*Location) NewFile ¶
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 (*Location) NewLocation ¶
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.