forked from mirror/pkger
ReadFile
This commit is contained in:
parent
9c88246fad
commit
b81555d655
10
pkger.go
10
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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue