This commit is contained in:
Mark Bates 2019-08-19 14:56:20 +01:00
parent 9c88246fad
commit b81555d655
2 changed files with 20 additions and 0 deletions

View File

@ -7,6 +7,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"log" "log"
"sync" "sync"
@ -24,6 +25,15 @@ var packed bool
var packMU = &sync.RWMutex{} 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{}) { func dubeg(key, format string, args ...interface{}) {
s := fmt.Sprintf(format, args...) s := fmt.Sprintf(format, args...)
debug.Debug("[%s|%s] %s", key, s) debug.Debug("[%s|%s] %s", key, s)

View File

@ -3,10 +3,20 @@ package pkger
import ( import (
"io" "io"
"strings" "strings"
"testing"
"github.com/stretchr/testify/require"
) )
const curPkg = "github.com/markbates/pkger" 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) { func createFile(p string, body ...string) (*File, error) {
if len(body) == 0 { if len(body) == 0 {
body = append(body, radio) body = append(body, radio)