diff --git a/client/object_get.go b/client/object_get.go index 55fe239..373cdda 100644 --- a/client/object_get.go +++ b/client/object_get.go @@ -342,6 +342,44 @@ func (c *Client) ObjectGetInit(ctx context.Context, prm PrmObjectGet) (*ObjectRe 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. type PrmObjectHead struct { prmObjectRead