mirror of https://github.com/talgo-cloud/bimg.git
parent
ef10d7d7ec
commit
37dd5f1d27
@ -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
|
||||
}
|
||||
@ -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")
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue