2020-05-08 14:37:43 +00:00
|
|
|
package distribyted
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2020-07-14 11:55:08 +00:00
|
|
|
"path"
|
2020-05-08 14:37:43 +00:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
type binaryFileSystem struct {
|
2020-07-14 11:55:08 +00:00
|
|
|
fs http.FileSystem
|
|
|
|
base string
|
2020-05-08 14:37:43 +00:00
|
|
|
}
|
|
|
|
|
2020-07-14 11:55:08 +00:00
|
|
|
func NewBinaryFileSystem(fs http.FileSystem, base string) *binaryFileSystem {
|
|
|
|
return &binaryFileSystem{
|
|
|
|
fs: fs,
|
|
|
|
base: base,
|
|
|
|
}
|
2020-05-08 14:37:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2020-07-14 11:55:08 +00:00
|
|
|
|
|
|
|
func (fs *binaryFileSystem) Open(name string) (http.File, error) {
|
|
|
|
return fs.fs.Open(path.Join(fs.base, name))
|
|
|
|
}
|