[#1319] services/object: Store payload directly in distributedTarget

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-04-28 10:18:14 +03:00 committed by LeL
parent 9da7df4d42
commit 4ea03c01b5

View file

@ -22,7 +22,7 @@ type distributedTarget struct {
obj *objectSDK.Object obj *objectSDK.Object
chunks [][]byte payload []byte
nodeTargetInitializer func(nodeDesc) transformer.ObjectTarget nodeTargetInitializer func(nodeDesc) transformer.ObjectTarget
@ -107,25 +107,13 @@ func (t *distributedTarget) WriteHeader(obj *objectSDK.Object) error {
} }
func (t *distributedTarget) Write(p []byte) (n int, err error) { func (t *distributedTarget) Write(p []byte) (n int, err error) {
t.chunks = append(t.chunks, p) t.payload = append(t.payload, p...)
return len(p), nil return len(p), nil
} }
func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) { func (t *distributedTarget) Close() (*transformer.AccessIdentifiers, error) {
sz := 0 t.obj.SetPayload(t.payload)
for i := range t.chunks {
sz += len(t.chunks[i])
}
payload := make([]byte, 0, sz)
for i := range t.chunks {
payload = append(payload, t.chunks[i]...)
}
t.obj.SetPayload(payload)
if err := t.fmt.ValidateContent(t.obj); err != nil { if err := t.fmt.ValidateContent(t.obj); err != nil {
return nil, fmt.Errorf("(%T) could not validate payload content: %w", t, err) return nil, fmt.Errorf("(%T) could not validate payload content: %w", t, err)