package erasurecode import ( "context" "crypto/ecdsa" objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object" "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object/transformer" ) // Target accepts regular objects and splits them into erasure-coded chunks. type Target struct { c *Constructor key *ecdsa.PrivateKey next transformer.ObjectWriter } // ObjectWriter is an interface of the object writer that writes prepared object. type ObjectWriter interface { WriteObject(context.Context, *objectSDK.Object) error } // NewTarget returns new target instance. func NewTarget(c *Constructor, key *ecdsa.PrivateKey, next ObjectWriter) *Target { return &Target{ c: c, key: key, next: next, } } // WriteObject implements the transformer.ObjectWriter interface. func (t *Target) WriteObject(ctx context.Context, obj *objectSDK.Object) error { parts, err := t.c.Split(obj, t.key) if err != nil { return err } for i := range parts { if err := t.next.WriteObject(ctx, parts[i]); err != nil { return err } } return nil }