[#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:
parent
abf9ad3573
commit
3880315a3f
2 changed files with 16 additions and 4 deletions
|
@ -5,7 +5,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Prm struct {
|
type Prm struct {
|
||||||
local bool
|
local, full bool
|
||||||
|
|
||||||
addr *object.Address
|
addr *object.Address
|
||||||
|
|
||||||
|
@ -37,3 +37,11 @@ func (p *Prm) WithRange(v *object.Range) *Prm {
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Prm) FullRange() *Prm {
|
||||||
|
if p != nil {
|
||||||
|
p.full = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
|
@ -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)
|
return nil, errors.Wrapf(err, "(%T) could not receive Head result", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
off, ln := prm.rng.GetOffset(), prm.rng.GetLength()
|
|
||||||
|
|
||||||
origin := headResult.Header()
|
origin := headResult.Header()
|
||||||
|
|
||||||
originSize := origin.GetPayloadSize()
|
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)
|
return nil, errors.Errorf("(%T) requested payload range is out-of-bounds", s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue