diff --git a/file.go b/file.go new file mode 100644 index 0000000..4b2b652 --- /dev/null +++ b/file.go @@ -0,0 +1,20 @@ +package bimg + +import ( + "io/ioutil" + "os" +) + +func Read(path string) ([]byte, error) { + data, err := os.Open(path) + if err != nil { + return nil, err + } + + buf, err := ioutil.ReadAll(data) + if err != nil { + return nil, err + } + + return buf, nil +} diff --git a/file_test.go b/file_test.go new file mode 100644 index 0000000..8ca2a41 --- /dev/null +++ b/file_test.go @@ -0,0 +1,21 @@ +package bimg + +import ( + "testing" +) + +func TestRead(t *testing.T) { + buf, err := Read("fixtures/test.jpg") + + if err != nil { + t.Errorf("Cannot read the image: %#v", err) + } + + if len(buf) == 0 { + t.Fatal("Empty buffer") + } + + if DetermineImageType(buf) != JPEG { + t.Fatal("Image is not jpeg") + } +} diff --git a/image_test.go b/image_test.go index 0d6789c..4872835 100644 --- a/image_test.go +++ b/image_test.go @@ -3,12 +3,11 @@ package bimg import ( "io/ioutil" "os" - "path" "testing" ) func TestImageResize(t *testing.T) { - data, _ := os.Open(path.Join("fixtures/test.jpg")) + data, _ := os.Open("fixtures/test.jpg") buf, err := ioutil.ReadAll(data) image := NewImage(buf)