[#52] object/range: Add full range option to parameters

Add FullRange option to get range operation parameters that allows to get
payload range [0:object_size] w/o the actual knowledge of the object size.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-26 10:53:08 +03:00 committed by Alex Vanin
parent abf9ad3573
commit 3880315a3f
2 changed files with 16 additions and 4 deletions

View file

@ -5,7 +5,7 @@ import (
)
type Prm struct {
local bool
local, full bool
addr *object.Address
@ -37,3 +37,11 @@ func (p *Prm) WithRange(v *object.Range) *Prm {
return p
}
func (p *Prm) FullRange() *Prm {
if p != nil {
p.full = true
}
return p
}

View file

@ -64,12 +64,16 @@ func (s *Service) GetRange(ctx context.Context, prm *Prm) (*Result, error) {
return nil, errors.Wrapf(err, "(%T) could not receive Head result", s)
}
off, ln := prm.rng.GetOffset(), prm.rng.GetLength()
origin := headResult.Header()
originSize := origin.GetPayloadSize()
if originSize < off+ln {
if prm.full {
prm.rng = new(object.Range)
prm.rng.SetLength(originSize)
}
if originSize < prm.rng.GetOffset()+prm.rng.GetLength() {
return nil, errors.Errorf("(%T) requested payload range is out-of-bounds", s)
}