Documentation ¶
Index ¶
- Constants
- Variables
- func Exist(filepath string) bool
- func Glob(pattern string) ([]string, error)
- func GlobFS(fs FileSystem, pattern string) ([]string, error)
- func Load(filepath string) (reader io.ReadCloser, err error)
- func ResolvePath(path string) (string, error)
- func ResolvePathFS(fs FileSystem, 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 Loader
- type LoaderFunc
- type OSFileSystem
- type PathResolver
Constants ¶
const (
DefaultMaxFileSize = 3 * 1024 * 1024 // 3MByte
)
Variables ¶
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 FileSystem, pattern string) ([]string, error)
Glob is wrap function for filepath.Glob with use filesystem.FileSystem if FileSystem also implements PathResolver, use it to resolve path.
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 FileSystem, 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.
var ( // Default is a default FileSystem to be used by exported functions. Default FileSystem = 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 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) Store ¶
func (osfs *OSFileSystem) Store(fpath string) (writer io.WriteCloser, err error)
type PathResolver ¶
path resolver resolves file path on the filesystem.