Skip to content

Commit

Permalink
Reading gzipped files
Browse files Browse the repository at this point in the history
  • Loading branch information
danyalprout committed Mar 15, 2024
1 parent f13a195 commit 16d5431
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions common/storage/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ethereum/go-ethereum/log"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"io"
)

type S3Storage struct {
Expand Down Expand Up @@ -65,7 +66,7 @@ func (s *S3Storage) Read(ctx context.Context, hash common.Hash) (BlobData, error
return BlobData{}, ErrStorage
}
defer res.Close()
_, err = res.Stat()
stat, err := res.Stat()
if err != nil {
errResponse := minio.ToErrorResponse(err)
if errResponse.Code == "NoSuchKey" {
Expand All @@ -77,10 +78,19 @@ func (s *S3Storage) Read(ctx context.Context, hash common.Hash) (BlobData, error
}
}

// TODO: We may need to decode if it's gzipped
var reader io.ReadCloser = res
defer reader.Close()

if stat.Metadata.Get("Content-Encoding") == "gzip" {
reader, err = gzip.NewReader(reader)
if err != nil {
s.log.Warn("error creating gzip reader", "hash", hash.String(), "err", err)
return BlobData{}, ErrMarshaling
}
}

var data BlobData
err = json.NewDecoder(res).Decode(&data)
err = json.NewDecoder(reader).Decode(&data)
if err != nil {
s.log.Warn("error decoding blob", "hash", hash.String(), "err", err)
return BlobData{}, ErrMarshaling
Expand Down

0 comments on commit 16d5431

Please sign in to comment.