[#238] engine: Support raw flag in Head method

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-12-08 14:58:38 +03:00
parent da42ee3a26
commit 91d8e0a4de

View file

@ -11,6 +11,7 @@ import (
// HeadPrm groups the parameters of Head operation.
type HeadPrm struct {
addr *objectSDK.Address
raw bool
}
// HeadRes groups resulting values of Head operation.
@ -29,6 +30,17 @@ func (p *HeadPrm) WithAddress(addr *objectSDK.Address) *HeadPrm {
return p
}
// WithRaw is a Head option to set raw flag value. If flag is unset, then Head
// returns header of virtual object, otherwise it returns SplitInfo of virtual
// object.
func (p *HeadPrm) WithRaw(raw bool) *HeadPrm {
if p != nil {
p.raw = raw
}
return p
}
// Header returns the requested object header.
//
// Instance has empty payload.
@ -51,7 +63,8 @@ func (e *StorageEngine) Head(prm *HeadPrm) (*HeadRes, error) {
)
shPrm := new(shard.HeadPrm).
WithAddress(prm.addr)
WithAddress(prm.addr).
WithRaw(prm.raw)
e.iterateOverSortedShards(prm.addr, func(_ int, sh *shard.Shard) (stop bool) {
res, err := sh.Head(shPrm)
@ -102,3 +115,17 @@ func Head(storage *StorageEngine, addr *objectSDK.Address) (*object.Object, erro
return res.Header(), nil
}
// HeadRaw reads object header from local storage by provided address and raw
// flag.
func HeadRaw(storage *StorageEngine, addr *objectSDK.Address, raw bool) (*object.Object, error) {
res, err := storage.Head(new(HeadPrm).
WithAddress(addr).
WithRaw(raw),
)
if err != nil {
return nil, err
}
return res.Header(), nil
}