From e559312fbfbbe5760f9cbf7e616684d11559c62e Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 2 Mar 2022 17:27:32 +0300 Subject: [PATCH] [#346] neofs: Fix `ReadObject` implementation `ReadObject` method must read full object payload into memory when `WithHeader` and `WithPayload` are set and write it into heading part. Signed-off-by: Leonard Lyubich --- internal/neofs/neofs.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/neofs/neofs.go b/internal/neofs/neofs.go index e20517b91..97f0e0c89 100644 --- a/internal/neofs/neofs.go +++ b/internal/neofs/neofs.go @@ -420,9 +420,17 @@ func (x *NeoFS) ReadObject(ctx context.Context, prm layer.PrmObjectRead) (*layer return nil, fmt.Errorf("init full object reading via connection pool: %w", err) } + defer res.Payload.Close() + + payload, err := io.ReadAll(res.Payload) + if err != nil { + return nil, fmt.Errorf("read full object payload: %w", err) + } + + object.NewRawFrom(&res.Header).SetPayload(payload) + return &layer.ObjectPart{ - Head: &res.Header, - Payload: res.Payload, + Head: &res.Header, }, nil }