Skip to content

Commit

Permalink
added debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
adranwit committed Feb 6, 2024
1 parent 5ddf06c commit 77360e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 5 additions & 1 deletion gs/open.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func (s *storager) Open(ctx context.Context, location string, options ...storage
return reader, err
}

//Open return content reader and hash values if md5 or crc option is supplied or error
// Open return content reader and hash values if md5 or crc option is supplied or error
func (s *storager) open(ctx context.Context, location string, options []storage.Option) (io.ReadCloser, error) {
location = strings.Trim(location, "/")
call := s.Objects.Get(s.bucket, location)
Expand Down Expand Up @@ -58,8 +58,12 @@ func (s *storager) open(ctx context.Context, location string, options []storage.
var response *nhttp.Response
err = runWithRetries(ctx, func() error {
response, err = call.Download()
if err != nil && response != nil && response.Body != nil {
response.Body.Close()
}
return err
}, s)

if err != nil {
return nil, errors.Wrapf(err, "failed to open gs://%v/%v ", s.bucket, location)
}
Expand Down
9 changes: 7 additions & 2 deletions gs/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,17 @@ func (t *reader) Read(dest []byte) (int, error) {
var err error
err = runWithRetries(t.ctx, func() error {
response, err = t.call.Download()
if err != nil && response != nil && response.Body != nil {
response.Body.Close()
}
return err
}, t.storager)
if response.Body != nil {
defer response.Body.Close()
}
if err != nil {
return 0, err
}
defer response.Body.Close()
readSoFar := 0
for {
read, err := response.Body.Read(dest[readSoFar:])
Expand All @@ -67,7 +72,7 @@ func (t *reader) Read(dest []byte) (int, error) {
return readSoFar, nil
}

//NewReadSeeker create a reader seeker
// NewReadSeeker create a reader seeker
func NewReadSeeker(ctx context.Context, storager *storager, call *storage.ObjectsGetCall, size int) io.ReadSeeker {
return &reader{
ctx: ctx,
Expand Down

0 comments on commit 77360e6

Please sign in to comment.