2020-09-26 07:54:03 +00:00
|
|
|
package getsvc
|
|
|
|
|
|
|
|
import (
|
|
|
|
objectV2 "github.com/nspcc-dev/neofs-api-go/v2/object"
|
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/core/object"
|
2020-12-02 23:45:25 +00:00
|
|
|
objectSvc "github.com/nspcc-dev/neofs-node/pkg/services/object"
|
2020-09-26 07:54:03 +00:00
|
|
|
)
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
type streamObjectWriter struct {
|
|
|
|
objectSvc.GetObjectStream
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func (s *streamObjectWriter) WriteHeader(obj *object.Object) error {
|
|
|
|
p := new(objectV2.GetObjectPartInit)
|
|
|
|
|
|
|
|
objV2 := obj.ToV2()
|
|
|
|
p.SetObjectID(objV2.GetObjectID())
|
|
|
|
p.SetHeader(objV2.GetHeader())
|
|
|
|
p.SetSignature(objV2.GetSignature())
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *streamObjectWriter) WriteChunk(chunk []byte) error {
|
|
|
|
p := new(objectV2.GetObjectPartChunk)
|
|
|
|
p.SetChunk(chunk)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
|
|
}
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
func newResponse(p objectV2.GetObjectPart) *objectV2.GetResponse {
|
|
|
|
r := new(objectV2.GetResponse)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
body := new(objectV2.GetResponseBody)
|
|
|
|
r.SetBody(body)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
body.SetObjectPart(p)
|
2020-09-26 07:54:03 +00:00
|
|
|
|
2020-12-02 23:45:25 +00:00
|
|
|
return r
|
2020-09-26 07:54:03 +00:00
|
|
|
}
|