pkger/pkging/stuffing/stuffing.go

47 lines
707 B
Go
Raw Permalink Normal View History

2019-10-16 18:13:11 +03:00
package stuffing
2019-09-21 19:51:29 +03:00
import (
"io"
"github.com/markbates/pkger/here"
2019-10-16 18:13:11 +03:00
"github.com/markbates/pkger/pkging/mem"
2019-09-21 19:51:29 +03:00
"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
}
2019-10-16 18:13:11 +03:00
pkg, err := mem.New(cur)
2019-09-21 19:51:29 +03:00
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()
2019-10-15 23:40:45 +03:00
if err := pkg.Add(f); err != nil {
2019-09-21 19:51:29 +03:00
return err
}
return nil
}()
if err != nil {
return err
}
}
b, err := pkg.MarshalEmbed()
if err != nil {
return err
}
_, err = w.Write(b)
return err
}