tstor/binary_fs.go

34 lines
637 B
Go
Raw Normal View History

package distribyted
import (
"net/http"
2021-11-18 19:36:07 +00:00
"path/filepath"
"strings"
)
type binaryFileSystem struct {
fs http.FileSystem
base string
}
func NewBinaryFileSystem(fs http.FileSystem, base string) *binaryFileSystem {
return &binaryFileSystem{
fs: fs,
base: base,
}
}
func (fs *binaryFileSystem) Exists(prefix string, filepath string) bool {
if p := strings.TrimPrefix(filepath, prefix); len(p) < len(filepath) {
if _, err := fs.Open(p); err != nil {
return false
}
return true
}
return false
}
func (fs *binaryFileSystem) Open(name string) (http.File, error) {
2021-11-18 19:36:07 +00:00
return fs.fs.Open(filepath.Join(fs.base, name))
}