[#1115] blobovnicza: remove GetRange method

It is unused and incorrect as described in FIXME.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-02-07 18:45:03 +03:00 committed by Alex Vanin
parent 18f6fba6ea
commit f9d3111825

View file

@ -1,72 +0,0 @@
package blobovnicza
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/core/object"
objectSDK "github.com/nspcc-dev/neofs-sdk-go/object"
addressSDK "github.com/nspcc-dev/neofs-sdk-go/object/address"
)
// GetRangePrm groups the parameters of GetRange operation.
type GetRangePrm struct {
addr *addressSDK.Address
rng *objectSDK.Range
}
// GetRangeRes groups resulting values of GetRange operation.
type GetRangeRes struct {
rngData []byte
}
// SetAddress sets address of the requested object.
func (p *GetRangePrm) SetAddress(addr *addressSDK.Address) {
p.addr = addr
}
// SetRange sets range of the requested payload data .
func (p *GetRangePrm) SetRange(rng *objectSDK.Range) {
p.rng = rng
}
// RangeData returns the requested payload data range.
func (p *GetRangeRes) RangeData() []byte {
return p.rngData
}
// GetRange reads range of the object from Blobovnicza by address.
//
// Returns any error encountered that
// did not allow to completely read the object.
//
// Returns ErrNotFound if requested object is not
// presented in Blobovnicza. Returns ErrRangeOutOfBounds
// if requested range is outside the payload.
func (b *Blobovnicza) GetRange(prm *GetRangePrm) (*GetRangeRes, error) {
res, err := b.Get(&GetPrm{
addr: prm.addr,
})
if err != nil {
return nil, err
}
// FIXME: code below is incorrect because Get returns raw object data
// so we should unmarshal payload from it before. If blobovnicza
// stores objects in non-protocol format (e.g. compressed)
// then it should not provide GetRange method.
from := prm.rng.GetOffset()
to := from + prm.rng.GetLength()
payload := res.obj
if from > to {
return nil, fmt.Errorf("invalid range [%d:%d]", from, to)
} else if uint64(len(payload)) < to {
return nil, object.ErrRangeOutOfBounds
}
return &GetRangeRes{
rngData: payload[from:to],
}, nil
}