Skip to content

Commit

Permalink
COS: Add size info into reader for pass it to Upload function.
Browse files Browse the repository at this point in the history
Signed-off-by: Jimmie Han <hanjinming@outlook.com>
  • Loading branch information
hanjm committed Feb 17, 2022
1 parent 792cc40 commit 8e3b658
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/objstore/cos/cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ func (b *Bucket) Upload(ctx context.Context, name string, r io.Reader) error {
const partSize = 1024 * 1024 * 128
partNums, lastSlice := int(math.Floor(float64(size)/partSize)), size%partSize
if partNums == 0 {
r := newFixedLengthReader(r, size)
if _, err := b.client.Object.Put(ctx, name, r, nil); err != nil {
return errors.Wrapf(err, "Put object: %s", name)
}
Expand Down Expand Up @@ -333,8 +334,19 @@ func (b *Bucket) getRange(ctx context.Context, name string, off, length int64) (
runutil.ExhaustCloseWithLogOnErr(b.logger, resp.Body, "cos get range obj close")
return nil, err
}
// Add size info into reader for pass it to Upload function.
r := objectSizerReadCloser{ReadCloser: resp.Body, size: resp.ContentLength}
return r, nil
}

type objectSizerReadCloser struct {
io.ReadCloser
size int64
}

return resp.Body, nil
// ObjectSize implement objstore.ObjectSizer.
func (o objectSizerReadCloser) ObjectSize() (int64, error) {
return o.size, nil
}

// Get returns a reader for the given object name.
Expand Down

0 comments on commit 8e3b658

Please sign in to comment.