diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2017-08-08 08:05:52 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2017-09-26 21:35:40 +0200 |
commit | bab0697f0e8a98cfa28c7527ee616e954c7afe91 (patch) | |
tree | 33c602bf39c4707ab4826ed6ba25c403cb07fe70 /fs | |
parent | a845956238e6a41479a7abd59f5c39e71f3f85f4 (diff) | |
download | petrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.tar.gz petrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.tar.bz2 petrific-bab0697f0e8a98cfa28c7527ee616e954c7afe91.zip |
Add OpenWritable to fs interfaces
Diffstat (limited to 'fs')
-rw-r--r-- | fs/fs.go | 3 | ||||
-rw-r--r-- | fs/memory.go | 6 | ||||
-rw-r--r-- | fs/os.go | 10 |
3 files changed, 16 insertions, 3 deletions
@@ -23,7 +23,8 @@ type File interface { type RegularFile interface { File - Open() (io.ReadWriteCloser, error) + Open() (io.ReadCloser, error) + OpenWritable() (io.WriteCloser, error) } type Dir interface { diff --git a/fs/memory.go b/fs/memory.go index 221ff36..2bc11dc 100644 --- a/fs/memory.go +++ b/fs/memory.go @@ -40,7 +40,11 @@ type memfsFile struct { func (memfsFile) Type() FileType { return FFile } -func (f memfsFile) Open() (io.ReadWriteCloser, error) { +func (f memfsFile) Open() (io.ReadCloser, error) { + return f, nil +} + +func (f memfsFile) OpenWritable() (io.WriteCloser, error) { return f, nil } @@ -58,7 +58,7 @@ func (f osFile) Delete() error { return os.RemoveAll(f.fullpath) } -func (f osFile) Open() (io.ReadWriteCloser, error) { +func (f osFile) Open() (io.ReadCloser, error) { fh, err := os.Open(f.fullpath) if err != nil { return nil, err @@ -66,6 +66,14 @@ func (f osFile) Open() (io.ReadWriteCloser, error) { return fh, nil } +func (f osFile) OpenWritable() (io.WriteCloser, error) { + fh, err := os.Create(f.fullpath) + if err != nil { + return nil, err + } + return fh, nil +} + func (f osFile) Readdir() (list []File, err error) { fh, err := os.Open(f.fullpath) if err != nil { |