Documentation ¶
Index ¶
- Constants
- Variables
- func Exist(filepath string) bool
- func Glob(pattern string) ([]string, error)
- func GlobFS(fs FileSystemPR, pattern string) ([]string, error)
- func Load(filepath string) (reader io.ReadCloser, err error)
- func ResolvePath(path string) (string, error)
- func ResolvePathFS(fs FileSystemPR, path string) (string, error)
- func Store(filepath string) (io.WriteCloser, error)
- func StringReadCloser(content string) (io.ReadCloser, error)
- type AbsPathFileSystem
- func (absfs *AbsPathFileSystem) Exist(fpath string) bool
- func (absfs *AbsPathFileSystem) Load(fpath string) (reader io.ReadCloser, err error)
- func (absfs *AbsPathFileSystem) ResolvePath(fpath string) (string, error)
- func (absfs *AbsPathFileSystem) Store(fpath string) (writer io.WriteCloser, err error)
- type FileSystem
- type FileSystemPR
- type Loader
- type LoaderFunc
- type NopPathResolver
- type OSFileSystem
- type PathResolver
- type RFileSystemPR
- type WatchEvent
- type WatchOp
- type Watcher
Constants ¶
const ( WatchOpCreate = fsnotify.Create WatchOpWrite = fsnotify.Write WatchOpRemove = fsnotify.Remove WatchOpRename = fsnotify.Rename WatchOpChmod = fsnotify.Chmod )
const (
DefaultMaxFileSize = 3 * 1024 * 1024 // 3MByte
)
Variables ¶
var ( ErrNonExistentWatch = fsnotify.ErrNonExistentWatch ErrEventOverflow = fsnotify.ErrEventOverflow )
var ( // Mobile is a FileSystem for the mobile environment that // requires absolute path to access file since the notion of // current directory is different from desktop. Mobile = &AbsPathFileSystem{ CurrentDir: "", Backend: Desktop, } )
Functions ¶
func GlobFS ¶
func GlobFS(fs FileSystemPR, pattern string) ([]string, error)
Glob is wrap function for filepath.Glob with use filesystem.FileSystemPR
func ResolvePath ¶
ResolvePath resolve file path under filesystem.Default. if Default also implements PathResolver, use it to resolve path, otherwise returns path itself.
func ResolvePathFS ¶
func ResolvePathFS(fs FileSystemPR, path string) (string, error)
ResolvePathFS resolve file path under given FileSystem. if FileSystem also implements PathResolver, use it to resolve path, otherwise returns path itself.
func StringReadCloser ¶
func StringReadCloser(content string) (io.ReadCloser, error)
StringReadCloser is helper function which creates io.ReadCloser from a entire content to adapt Loader interface.
Types ¶
type AbsPathFileSystem ¶
type AbsPathFileSystem struct { CurrentDir string Backend FileSystem }
AbsPathFileSystem completes absolute path for every file access. The absolute path is made by using filepath.Abs when CurrentDir is set to empty, or made by file.Join(CurrentDir, relativePath) when CurrentDir is set. The Backend is used to access File API. and The OSFileSystem is used as Backend when it is nil.
func (*AbsPathFileSystem) Exist ¶
func (absfs *AbsPathFileSystem) Exist(fpath string) bool
func (*AbsPathFileSystem) Load ¶
func (absfs *AbsPathFileSystem) Load(fpath string) (reader io.ReadCloser, err error)
func (*AbsPathFileSystem) ResolvePath ¶
func (absfs *AbsPathFileSystem) ResolvePath(fpath string) (string, error)
ResolvePath complete parent directory path to fpath when fpath is a relative path. It returns fpath itself when fpath is already absolute path.
func (*AbsPathFileSystem) Store ¶
func (absfs *AbsPathFileSystem) Store(fpath string) (writer io.WriteCloser, err error)
type FileSystem ¶
type FileSystem interface { Loader // create data store entry. Store(filepath string) (io.WriteCloser, error) }
abstraction for the filesystem.
type FileSystemPR ¶ added in v0.7.0
type FileSystemPR interface { FileSystem PathResolver }
FileSystemPR is a composit interface with FileSystem and PathResolver interfaces.
var ( // Default is a default FileSystem to be used by exported functions. Default FileSystemPR = Desktop )
type Loader ¶
type Loader interface { // Load loads content specified by the relative path // from erago system root directory. // It returns io.Reader for the loaded content with no error, // or returns nil with file loading error. Load(filepath string) (reader io.ReadCloser, err error) // Exist checks whether given filepath exist from erago system root directory. // It returns true when the filepath exists, otherwise return false. Exist(filepath string) bool }
Loader is a platform depended file loader which searches file path and return its content as io.Reader.
var ( // Desktop is a FileSystem for the desktop environment Desktop = &OSFileSystem{MaxFileSize: DefaultMaxFileSize} // String is a adaptation of strings.Buffer with Loader interface. String Loader = LoaderFunc(StringReadCloser) )
type LoaderFunc ¶
type LoaderFunc func(string) (io.ReadCloser, error)
LoaderFunc implements Loader interface.
func (LoaderFunc) Exist ¶
func (fn LoaderFunc) Exist(filepath string) bool
func (LoaderFunc) Load ¶
func (fn LoaderFunc) Load(filepath string) (reader io.ReadCloser, err error)
type NopPathResolver ¶ added in v0.7.0
type NopPathResolver struct{}
NopPathResolver implements PathResolver interface.
func (NopPathResolver) ResolvePath ¶ added in v0.7.0
func (NopPathResolver) ResolvePath(path string) (string, error)
ResolvePath returns path as is and no error.
type OSFileSystem ¶
type OSFileSystem struct {
MaxFileSize int64 // in bytes
}
OSFileSystem is a adaptation of the os.Open() with Loader interface.
func (*OSFileSystem) Exist ¶
func (osfs *OSFileSystem) Exist(filepath string) bool
func (*OSFileSystem) Load ¶
func (osfs *OSFileSystem) Load(filepath string) (reader io.ReadCloser, err error)
func (*OSFileSystem) ResolvePath ¶ added in v0.7.0
func (osfs *OSFileSystem) ResolvePath(fpath string) (string, error)
func (*OSFileSystem) Store ¶
func (osfs *OSFileSystem) Store(fpath string) (writer io.WriteCloser, err error)
type PathResolver ¶
path resolver resolves file path on the filesystem.
type RFileSystemPR ¶ added in v0.7.0
type RFileSystemPR interface { Loader PathResolver }
RFileSystemPR is a Readonly FileSystemPR interface.
type WatchEvent ¶ added in v0.7.0
Export some types and values so that user need not import underlying package explicitly
type Watcher ¶ added in v0.7.0
type Watcher interface { Watch(filepath string) error UnWatch(filepath string) error Events() <-chan WatchEvent Errors() <-chan error Close() error }
func OpenWatcher ¶ added in v0.7.0
OpenWatcher creates Watcher interface from Default FileSystem. Note that returned watcher must call Close() after use.
func OpenWatcherPR ¶ added in v0.7.0
func OpenWatcherPR(pr PathResolver) (Watcher, error)
OpenWatcherPR creates Watcher interface from given PathResolver.