a5ebdd1891
Replace local placement tool in order to reuse it in different object services. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
39 lines
906 B
Go
39 lines
906 B
Go
package putsvc
|
|
|
|
import (
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
|
"github.com/nspcc-dev/neofs-node/pkg/local_object_storage/localstore"
|
|
"github.com/nspcc-dev/neofs-node/pkg/services/object_manager/transformer"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
type localTarget struct {
|
|
storage *localstore.Storage
|
|
|
|
obj *object.RawObject
|
|
|
|
payload []byte
|
|
}
|
|
|
|
func (t *localTarget) WriteHeader(obj *object.RawObject) error {
|
|
t.obj = obj
|
|
|
|
t.payload = make([]byte, 0, obj.GetPayloadSize())
|
|
|
|
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 := t.storage.Put(t.obj.Object()); err != nil {
|
|
return nil, errors.Wrapf(err, "(%T) could not put object to local storage", t)
|
|
}
|
|
|
|
return new(transformer.AccessIdentifiers).
|
|
WithSelfID(t.obj.GetID()), nil
|
|
}
|