summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/GeertJohan/go.rice/file.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-02-18 23:00:46 +0100
committerWim <wim@42.be>2017-02-18 23:11:48 +0100
commit930b639cc9cd2d2873302f30303378c0e53816a8 (patch)
tree8cd3f1d464fb5d4e5607fe16255c35a31a9d8b62 /vendor/github.com/GeertJohan/go.rice/file.go
parent58483ea70c2c99a352592c5e50686fb03985650e (diff)
downloadmatterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.gz
matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.tar.bz2
matterbridge-msglm-930b639cc9cd2d2873302f30303378c0e53816a8.zip
Update vendor
Diffstat (limited to 'vendor/github.com/GeertJohan/go.rice/file.go')
-rw-r--r--vendor/github.com/GeertJohan/go.rice/file.go144
1 files changed, 144 insertions, 0 deletions
diff --git a/vendor/github.com/GeertJohan/go.rice/file.go b/vendor/github.com/GeertJohan/go.rice/file.go
new file mode 100644
index 00000000..606a1885
--- /dev/null
+++ b/vendor/github.com/GeertJohan/go.rice/file.go
@@ -0,0 +1,144 @@
+package rice
+
+import (
+ "bytes"
+ "errors"
+ "os"
+ "path/filepath"
+)
+
+// File implements the io.Reader, io.Seeker, io.Closer and http.File interfaces
+type File struct {
+ // File abstracts file methods so the user doesn't see the difference between rice.virtualFile, rice.virtualDir and os.File
+ // TODO: maybe use internal File interface and four implementations: *os.File, appendedFile, virtualFile, virtualDir
+
+ // real file on disk
+ realF *os.File
+
+ // when embedded (go)
+ virtualF *virtualFile
+ virtualD *virtualDir
+
+ // when appended (zip)
+ appendedF *appendedFile
+ appendedFileReader *bytes.Reader
+ // TODO: is appendedFileReader subject of races? Might need a lock here..
+}
+
+// Close is like (*os.File).Close()
+// Visit http://golang.org/pkg/os/#File.Close for more information
+func (f *File) Close() error {
+ if f.appendedF != nil {
+ if f.appendedFileReader == nil {
+ return errors.New("already closed")
+ }
+ f.appendedFileReader = nil
+ return nil
+ }
+ if f.virtualF != nil {
+ return f.virtualF.close()
+ }
+ if f.virtualD != nil {
+ return f.virtualD.close()
+ }
+ return f.realF.Close()
+}
+
+// Stat is like (*os.File).Stat()
+// Visit http://golang.org/pkg/os/#File.Stat for more information
+func (f *File) Stat() (os.FileInfo, error) {
+ if f.appendedF != nil {
+ if f.appendedF.dir {
+ return f.appendedF.dirInfo, nil
+ }
+ if f.appendedFileReader == nil {
+ return nil, errors.New("file is closed")
+ }
+ return f.appendedF.zipFile.FileInfo(), nil
+ }
+ if f.virtualF != nil {
+ return f.virtualF.stat()
+ }
+ if f.virtualD != nil {
+ return f.virtualD.stat()
+ }
+ return f.realF.Stat()
+}
+
+// Readdir is like (*os.File).Readdir()
+// Visit http://golang.org/pkg/os/#File.Readdir for more information
+func (f *File) Readdir(count int) ([]os.FileInfo, error) {
+ if f.appendedF != nil {
+ if f.appendedF.dir {
+ fi := make([]os.FileInfo, 0, len(f.appendedF.children))
+ for _, childAppendedFile := range f.appendedF.children {
+ if childAppendedFile.dir {
+ fi = append(fi, childAppendedFile.dirInfo)
+ } else {
+ fi = append(fi, childAppendedFile.zipFile.FileInfo())
+ }
+ }
+ return fi, nil
+ }
+ //++ TODO: is os.ErrInvalid the correct error for Readdir on file?
+ return nil, os.ErrInvalid
+ }
+ if f.virtualF != nil {
+ return f.virtualF.readdir(count)
+ }
+ if f.virtualD != nil {
+ return f.virtualD.readdir(count)
+ }
+ return f.realF.Readdir(count)
+}
+
+// Read is like (*os.File).Read()
+// Visit http://golang.org/pkg/os/#File.Read for more information
+func (f *File) Read(bts []byte) (int, error) {
+ if f.appendedF != nil {
+ if f.appendedFileReader == nil {
+ return 0, &os.PathError{
+ Op: "read",
+ Path: filepath.Base(f.appendedF.zipFile.Name),
+ Err: errors.New("file is closed"),
+ }
+ }
+ if f.appendedF.dir {
+ return 0, &os.PathError{
+ Op: "read",
+ Path: filepath.Base(f.appendedF.zipFile.Name),
+ Err: errors.New("is a directory"),
+ }
+ }
+ return f.appendedFileReader.Read(bts)
+ }
+ if f.virtualF != nil {
+ return f.virtualF.read(bts)
+ }
+ if f.virtualD != nil {
+ return f.virtualD.read(bts)
+ }
+ return f.realF.Read(bts)
+}
+
+// Seek is like (*os.File).Seek()
+// Visit http://golang.org/pkg/os/#File.Seek for more information
+func (f *File) Seek(offset int64, whence int) (int64, error) {
+ if f.appendedF != nil {
+ if f.appendedFileReader == nil {
+ return 0, &os.PathError{
+ Op: "seek",
+ Path: filepath.Base(f.appendedF.zipFile.Name),
+ Err: errors.New("file is closed"),
+ }
+ }
+ return f.appendedFileReader.Seek(offset, whence)
+ }
+ if f.virtualF != nil {
+ return f.virtualF.seek(offset, whence)
+ }
+ if f.virtualD != nil {
+ return f.virtualD.seek(offset, whence)
+ }
+ return f.realF.Seek(offset, whence)
+}