package ricefs import ( "io" "os" "github.com/GeertJohan/go.rice" "github.com/spf13/afero" ) var _ afero.File = &file{} type file struct { f *rice.File info os.FileInfo } func (f *file) Close() error { return f.f.Close() } func (f *file) Read(p []byte) (int, error) { return f.f.Read(p) } func (f *file) ReadAt(p []byte, off int64) (int, error) { _, err := f.Seek(off, io.SeekStart) if nil != err { return 0, err } return f.Read(p) } func (f *file) Seek(off int64, whence int) (int64, error) { return f.f.Seek(off, whence) } func (f *file) Write(p []byte) (int, error) { return 0, ErrReadOnly } func (f *file) WriteAt(p []byte, off int64) (int, error) { return 0, ErrReadOnly } func (f *file) Name() string { i, err := f.Stat() if nil != err { return "" } return i.Name() } func (f *file) Readdir(n int) ([]os.FileInfo, error) { return f.f.Readdir(n) } func (f *file) Readdirnames(n int) ([]string, error) { var dirs, err = f.Readdir(n) if nil != err { return nil, err } var names = make([]string, len(dirs)) for i, dir := range dirs { names[i] = dir.Name() } return names, nil } func (f *file) Stat() (os.FileInfo, error) { if nil == f.info { i, err := f.f.Stat() if nil != err { return nil, err } f.info = i } return f.info, nil } func (f *file) Sync() error { return ErrReadOnly } func (f *file) Truncate(size int64) error { return ErrReadOnly } func (f *file) WriteString(s string) (int, error) { return 0, ErrReadOnly }