diff --git a/storage.go b/storage.go index 45b8693..37654e5 100644 --- a/storage.go +++ b/storage.go @@ -6,6 +6,7 @@ import ( "errors" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" + "io" "net/http" "os" "path/filepath" @@ -136,10 +137,11 @@ func (s *Storage) Read(name string) ([]byte, error) { } } - var objectBytes []byte - if _, err := object.Read(objectBytes); err != nil { + objectBytes, err := io.ReadAll(object) + if err != nil { return nil, err } + return objectBytes, nil } else { return os.ReadFile(filepath.Join(s.config.Path, name)) diff --git a/storage_test.go b/storage_test.go index ae89b97..370e91a 100644 --- a/storage_test.go +++ b/storage_test.go @@ -1,6 +1,7 @@ package fsys import ( + "fmt" "github.com/stretchr/testify/assert" "io" "testing" @@ -18,12 +19,17 @@ func TestStorageLocal(t *testing.T) { err = stor.Write("test.txt", []byte("hi"), WriteOptions{}) assert.NoError(t, err) + t.Log("== Read ==") + fileContent, err := stor.Read("test.txt") + assert.NoError(t, err) + assert.Equal(t, []byte("hi"), fileContent) + t.Log("== Open ==") file, err := stor.Open("test.txt") assert.NoError(t, err) assert.Equal(t, "test.txt", file.Name) - fileContent, err := io.ReadAll(file) + fileContent, err = io.ReadAll(file) assert.NoError(t, err) assert.Equal(t, []byte("hi"), fileContent) @@ -47,12 +53,18 @@ func TestStorageS3(t *testing.T) { err = stor.Write("test.txt", []byte("hi"), WriteOptions{}) assert.NoError(t, err) + t.Log("== Read ==") + fileContent, err := stor.Read("test.txt") + assert.NoError(t, err) + fmt.Println(fileContent) + assert.Equal(t, []byte("hi"), fileContent) + t.Log("== Open ==") file, err := stor.Open("test.txt") assert.NoError(t, err) assert.Equal(t, "test.txt", file.Name) - fileContent, err := io.ReadAll(file) + fileContent, err = io.ReadAll(file) assert.NoError(t, err) assert.Equal(t, []byte("hi"), fileContent)