Skip to content

Commit

Permalink
Use io.ReadAll on reader
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Jun 8, 2023
1 parent e1906bc commit 2814a43
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions blob.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package blobs

import (
"bytes"
"context"
"io"
"time"
Expand Down Expand Up @@ -46,38 +45,13 @@ func (blob *Blob) CreatedAt() (time.Time, error) {

// Returns the content of the blob as a byte slice.
func (blob *Blob) Content(ctx context.Context) ([]byte, error) {
var b bytes.Buffer
var buf = make([]byte, blob.chunkSize*blob.chunksPerTransaction)
r, err := blob.Reader()

if err != nil {
return b.Bytes(), err
return []byte{}, err
}

for {
err := ctx.Err()
if err != nil {
return b.Bytes(), err
}

n, err := r.Read(buf)

if n > 0 {
_, err := b.Write(buf[:n])
if err != nil {
return b.Bytes(), err
}
}

if err == io.EOF {
return b.Bytes(), nil
}

if err != nil {
return b.Bytes(), err
}

}
return io.ReadAll(r)
}

// Returns a new reader for the content of the blob.
Expand Down

0 comments on commit 2814a43

Please sign in to comment.