forked from mirror/pkger
33 lines
511 B
Go
33 lines
511 B
Go
package memwh
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/markbates/pkger/fs"
|
|
)
|
|
|
|
func (fx *Warehouse) Open(name string) (fs.File, error) {
|
|
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
|
|
}
|