forked from TrueCloudLab/frostfs-node
9dd83bdf0d
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
55 lines
1.4 KiB
Go
55 lines
1.4 KiB
Go
package blobstor
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
// GetRangeBigPrm groups the parameters of GetRangeBig operation.
|
|
type GetRangeBigPrm struct {
|
|
address
|
|
rwRange
|
|
}
|
|
|
|
// GetRangeBigRes groups resulting values of GetRangeBig operation.
|
|
type GetRangeBigRes struct {
|
|
rangeData
|
|
}
|
|
|
|
// GetRangeBig reads data of object payload range from shallow dir of BLOB storage.
|
|
//
|
|
// Returns any error encountered that
|
|
// did not allow to completely read the object payload range.
|
|
//
|
|
// Returns ErrRangeOutOfBounds if requested object range is out of bounds.
|
|
func (b *BlobStor) GetRangeBig(prm *GetRangeBigPrm) (*GetRangeBigRes, error) {
|
|
// get compressed object data
|
|
data, err := b.fsTree.get(prm.addr)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not read object from fs tree")
|
|
}
|
|
|
|
data, err = b.decompressor(data)
|
|
if err != nil {
|
|
return nil, errors.Wrap(err, "could not decompress object data")
|
|
}
|
|
|
|
// unmarshal the object
|
|
obj := object.New()
|
|
if err := obj.Unmarshal(data); err != nil {
|
|
return nil, errors.Wrap(err, "could not unmarshal the object")
|
|
}
|
|
|
|
payload := obj.Payload()
|
|
ln, off := prm.rng.GetLength(), prm.rng.GetOffset()
|
|
|
|
if pLen := uint64(len(payload)); pLen < ln+off {
|
|
return nil, object.ErrRangeOutOfBounds
|
|
}
|
|
|
|
return &GetRangeBigRes{
|
|
rangeData: rangeData{
|
|
data: payload[off : off+ln],
|
|
},
|
|
}, nil
|
|
}
|