From 139660c6ff5951a247c3a7a15cfa34ce87ab67b2 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 7 Dec 2020 19:06:11 +0300 Subject: [PATCH] [#225] pkg/client: Update object methods - Support errors with SplitInfo in head and range methods. - Support raw flat in range method. Signed-off-by: Alex Vanin --- pkg/client/object.go | 46 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/pkg/client/object.go b/pkg/client/object.go index 601bbdc4..fe317889 100644 --- a/pkg/client/object.go +++ b/pkg/client/object.go @@ -48,6 +48,8 @@ type ObjectHeaderParams struct { type RangeDataParams struct { addr *object.Address + raw bool + r *object.Range w io.Writer @@ -690,6 +692,10 @@ func (c *Client) getObjectHeaderV2(ctx context.Context, p *ObjectHeaderParams, o ); err != nil { return nil, errors.Wrap(err, "incorrect object header signature") } + case *v2object.SplitInfo: + si := object.NewSplitInfoFromV2(v) + + return nil, object.NewSplitInfoError(si) default: panic(fmt.Sprintf("unexpected Head object type %T", v)) } @@ -721,6 +727,22 @@ func (p *RangeDataParams) Address() *object.Address { return nil } +func (p *RangeDataParams) WithRaw(v bool) *RangeDataParams { + if p != nil { + p.raw = v + } + + return p +} + +func (p *RangeDataParams) Raw() bool { + if p != nil { + return p.raw + } + + return false +} + func (p *RangeDataParams) WithRange(v *object.Range) *RangeDataParams { if p != nil { p.r = v @@ -799,6 +821,7 @@ func (c *Client) objectPayloadRangeV2(ctx context.Context, p *RangeDataParams, o // fill body fields body.SetAddress(p.addr.ToV2()) body.SetRange(p.r.ToV2()) + body.SetRaw(p.raw) // sign the request if err := signature.SignServiceMessage(c.key, req); err != nil { @@ -832,14 +855,23 @@ func (c *Client) objectPayloadRangeV2(ctx context.Context, p *RangeDataParams, o return nil, errors.Wrapf(err, "could not verify %T", resp) } - chunk := resp.GetBody().GetChunk() - - if p.w != nil { - if _, err := p.w.Write(chunk); err != nil { - return nil, errors.Wrap(err, "could not write payload chunk") + switch v := resp.GetBody().GetRangePart().(type) { + case nil: + return nil, errNilObjectPart + case *v2object.GetRangePartChunk: + if p.w != nil { + if _, err = p.w.Write(v.GetChunk()); err != nil { + return nil, errors.Wrap(err, "could not write payload chunk") + } + } else { + payload = append(payload, v.GetChunk()...) } - } else { - payload = append(payload, chunk...) + case *v2object.SplitInfo: + si := object.NewSplitInfoFromV2(v) + + return nil, object.NewSplitInfoError(si) + default: + panic(fmt.Sprintf("unexpected GetRange object type %T", v)) } }