2019-09-02 00:58:20 +03:00
|
|
|
package memware
|
2019-09-01 00:00:24 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/markbates/pkger/fs"
|
|
|
|
)
|
|
|
|
|
2019-09-02 00:54:05 +03:00
|
|
|
func (fx *Warehouse) Open(name string) (fs.File, error) {
|
2019-09-01 00:00:24 +03:00
|
|
|
pt, err := fx.Parse(name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
fl, ok := fx.files.Load(pt)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("could not open %s", name)
|
|
|
|
}
|
|
|
|
f, ok := fl.(*File)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("could not open %s", name)
|
|
|
|
}
|
|
|
|
nf := &File{
|
|
|
|
fs: fx,
|
|
|
|
info: fs.WithName(f.info.Name(), f.info),
|
|
|
|
path: f.path,
|
|
|
|
data: f.data,
|
|
|
|
her: f.her,
|
|
|
|
}
|
|
|
|
|
|
|
|
return nf, nil
|
|
|
|
}
|