/
sub.go
69 lines (57 loc) · 1.57 KB
/
sub.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package storage
import (
"fmt"
"io"
"io/fs"
"os"
"path"
)
type sub struct {
Store Store
Base string
PropagateClose bool
}
func Sub(s Store, base string, propagateClose bool) Store {
s2, isSub := s.(*sub)
if isSub {
return &sub{s2.Store, path.Join(s2.Base, base), propagateClose}
} else {
return &sub{s, base, propagateClose}
}
}
func (s *sub) Url() string {
return s.Store.Url()
}
func (s *sub) ReadDir(name string, filter Filter) ([]fs.FileInfo, error) {
return s.Store.ReadDir(path.Join(s.Base, name), filter)
}
// Read reads data from a file into a writer
func (s *sub) Read(name string, rang *Range, dest io.Writer, progress chan int64) error {
return s.Store.Read(path.Join(s.Base, name), rang, dest, progress)
}
// Write writes data to a file name. An existing file is overwritten
func (s *sub) Write(name string, source io.ReadSeeker, progress chan int64) error {
return s.Store.Write(path.Join(s.Base, name), source, progress)
}
// Stat provides statistics about a file
func (s *sub) Stat(name string) (os.FileInfo, error) {
return s.Store.Stat(path.Join(s.Base, name))
}
// Delete deletes a file
func (s *sub) Delete(name string) error {
return s.Store.Delete(path.Join(s.Base, name))
}
// Close closes the store
func (s *sub) Close() error {
if s.PropagateClose {
return s.Store.Close()
}
return nil
}
// String returns a human-readable representation of the storer (e.g. sftp://user@host/path)
func (s *sub) String() string {
return fmt.Sprintf("%s/%s", s.Store, s.Base)
}
func (s *sub) Describe() Description {
return s.Store.Describe()
}