frostfs-node/pkg/services/object/put/local.go
Leonard Lyubich 7ccd1625af [#1214] *: Use single Object type in whole project
Remove `Object` and `RawObject` types from `pkg/core/object` package.
Use `Object` type from NeoFS SDK Go library everywhere. Avoid using the
deprecated elements.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
2022-03-04 17:45:00 +03:00

40 lines
869 B
Go

package putsvc
import (
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/engine"
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
"github.com/nspcc-dev/neofs-sdk-go/object"
)
type localTarget struct {
storage *engine.StorageEngine
obj *object.Object
payload []byte
}
func (t *localTarget) WriteHeader(obj *object.Object) error {
t.obj = obj
t.payload = make([]byte, 0, obj.PayloadSize())
return nil
}
func (t *localTarget) Write(p []byte) (n int, err error) {
t.payload = append(t.payload, p...)
return len(p), nil
}
func (t *localTarget) Close() (*transformer.AccessIdentifiers, error) {
if err := engine.Put(t.storage, t.obj); err != nil {
return nil, fmt.Errorf("(%T) could not put object to local storage: %w", t, err)
}
return new(transformer.AccessIdentifiers).
WithSelfID(t.obj.ID()), nil
}