[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-03-02 17:27:32 +03:00 committed by LeL
parent dc628aef22
commit e559312fbf

View file

@ -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) 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{ return &layer.ObjectPart{
Head: &res.Header, Head: &res.Header,
Payload: res.Payload,
}, nil }, nil
} }