forked from TrueCloudLab/frostfs-sdk-go
[#131] client: Add GetFullObject
helper function
Add helper function which accepts container and object identifiers and returns object instance read to the memory. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
32458baeb7
commit
b0f7f75929
1 changed files with 38 additions and 0 deletions
|
@ -342,6 +342,44 @@ func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectRe
|
||||||
return &r, nil
|
return &r, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetFullObject reads object header and full payload to the memory and returns
|
||||||
|
// the result.
|
||||||
|
//
|
||||||
|
// Function behavior equivalent to Client.ObjectGetInit, see documentation for details.
|
||||||
|
func GetFullObject(ctx context.Context, c *Client, idCnr cid.ID, idObj oid.ID) (*object.Object, error) {
|
||||||
|
var prm PrmObjectGet
|
||||||
|
|
||||||
|
prm.FromContainer(idCnr)
|
||||||
|
prm.ByID(idObj)
|
||||||
|
|
||||||
|
rdr, err := c.ObjectGetInit(ctx, prm)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("init object reading: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
var obj object.Object
|
||||||
|
|
||||||
|
if rdr.ReadHeader(&obj) {
|
||||||
|
payload, err := io.ReadAll(rdr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("read payload: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
object.NewRawFrom(&obj).SetPayload(payload)
|
||||||
|
}
|
||||||
|
|
||||||
|
res, err := rdr.Close()
|
||||||
|
if err == nil {
|
||||||
|
err = apistatus.ErrFromStatus(res.Status())
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("finish object reading: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &obj, nil
|
||||||
|
}
|
||||||
|
|
||||||
// PrmObjectHead groups parameters of ObjectHead operation.
|
// PrmObjectHead groups parameters of ObjectHead operation.
|
||||||
type PrmObjectHead struct {
|
type PrmObjectHead struct {
|
||||||
prmObjectRead
|
prmObjectRead
|
||||||
|
|
Loading…
Reference in a new issue