pkger/stuffing/stuffing.go

61 lines
1.1 KiB
Go
Raw Normal View History

2019-09-21 19:51:29 +03:00
package stuffing
import (
2019-10-09 20:21:54 +03:00
"fmt"
2019-09-21 19:51:29 +03:00
"io"
2019-10-09 20:21:54 +03:00
"strings"
2019-09-21 19:51:29 +03:00
"github.com/markbates/pkger/here"
"github.com/markbates/pkger/pkging"
"github.com/markbates/pkger/pkging/mem"
"github.com/markbates/pkger/pkging/stdos"
)
2019-10-09 20:21:54 +03:00
func Stuff(w io.Writer, cur here.Info, paths []here.Path) error {
disk, err := stdos.New(cur)
2019-09-21 19:51:29 +03:00
if err != nil {
return err
}
pkg, err := mem.New(cur)
if err != nil {
return err
}
for _, pt := range paths {
err = func() error {
f, err := disk.Open(pt.String())
if err != nil {
return err
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
return err
}
2019-10-09 20:21:54 +03:00
info := f.Info()
fmt.Println(">>>TODO stuffing/stuffing.go:41: info.Dir ", info.Dir)
fi = pkging.WithName(strings.TrimPrefix(fi.Name(), info.Dir), fi)
fmt.Println(">>>TODO stuffing/stuffing.go:37: fi.Name() ", fi.Name())
2019-09-21 19:51:29 +03:00
if err := pkg.Add(fi, f); err != nil {
return err
}
return nil
// WithInfo(ng, og)
}()
if err != nil {
return err
}
}
b, err := pkg.MarshalEmbed()
if err != nil {
return err
}
_, err = w.Write(b)
return err
}