diff --git a/pkger.go b/pkger.go index 7591728..4b31814 100644 --- a/pkger.go +++ b/pkger.go @@ -7,6 +7,7 @@ import ( "encoding/json" "fmt" "io" + "io/ioutil" "log" "sync" @@ -24,6 +25,15 @@ var packed bool var packMU = &sync.RWMutex{} +func ReadFile(s string) ([]byte, error) { + f, err := Open(s) + if err != nil { + return nil, err + } + defer f.Close() + return ioutil.ReadAll(f) +} + func dubeg(key, format string, args ...interface{}) { s := fmt.Sprintf(format, args...) debug.Debug("[%s|%s] %s", key, s) diff --git a/pkger_test.go b/pkger_test.go index ba597c7..aa6c240 100644 --- a/pkger_test.go +++ b/pkger_test.go @@ -3,10 +3,20 @@ package pkger import ( "io" "strings" + "testing" + + "github.com/stretchr/testify/require" ) const curPkg = "github.com/markbates/pkger" +func Test_ReadFile(t *testing.T) { + r := require.New(t) + b, err := ReadFile("/LICENSE") + r.NoError(err) + r.Contains(string(b), "MIT") +} + func createFile(p string, body ...string) (*File, error) { if len(body) == 0 { body = append(body, radio)