2020-11-17 16:29:00 +00:00
|
|
|
package blobstor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
objectSDK "github.com/nspcc-dev/neofs-api-go/pkg/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
|
|
"github.com/pkg/errors"
|
|
|
|
)
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
// GetBigPrm groups the parameters of GetBig operation.
|
|
|
|
type GetBigPrm struct {
|
2020-11-24 13:40:50 +00:00
|
|
|
address
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
// GetBigRes groups resulting values of GetBig operation.
|
|
|
|
type GetBigRes struct {
|
2020-11-24 13:40:50 +00:00
|
|
|
roObject
|
2020-11-17 16:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ErrObjectNotFound is returns on read operations requested on a missing object.
|
|
|
|
var ErrObjectNotFound = errors.New("object not found")
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
// GetBig reads the object from shallow dir of BLOB storage by address.
|
2020-11-17 16:29:00 +00:00
|
|
|
//
|
|
|
|
// Returns any error encountered that
|
2020-11-24 13:29:55 +00:00
|
|
|
// did not allow to completely read the object.
|
|
|
|
func (b *BlobStor) GetBig(prm *GetBigPrm) (*GetBigRes, error) {
|
2020-11-17 16:29:00 +00:00
|
|
|
// get compressed object data
|
|
|
|
data, err := b.fsTree.get(prm.addr)
|
|
|
|
if err != nil {
|
|
|
|
if errors.Is(err, errFileNotFound) {
|
|
|
|
return nil, ErrObjectNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2020-11-24 13:29:55 +00:00
|
|
|
return &GetBigRes{
|
2020-11-24 13:40:50 +00:00
|
|
|
roObject: roObject{
|
|
|
|
obj: obj,
|
|
|
|
},
|
2020-11-17 16:29:00 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t *fsTree) get(addr *objectSDK.Address) ([]byte, error) {
|
|
|
|
p := t.treePath(addr)
|
|
|
|
|
|
|
|
if _, err := os.Stat(p); os.IsNotExist(err) {
|
|
|
|
return nil, errFileNotFound
|
|
|
|
}
|
|
|
|
|
|
|
|
return ioutil.ReadFile(p)
|
|
|
|
}
|