[#52] object/range: Attach received object header to result

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-09-26 10:50:50 +03:00 committed by Alex Vanin
parent 0490107165
commit abf9ad3573
3 changed files with 30 additions and 9 deletions

View file

@ -1,5 +1,15 @@
package rangesvc
import (
"github.com/nspcc-dev/neofs-node/pkg/core/object"
)
type Result struct {
head *object.Object
stream Streamer
}
type Response struct {
chunk []byte
}
@ -7,3 +17,11 @@ type Response struct {
func (r *Response) PayloadChunk() []byte {
return r.chunk
}
func (r *Result) Head() *object.Object {
return r.head
}
func (r *Result) Stream() Streamer {
return r.stream
}

View file

@ -55,7 +55,7 @@ func NewService(opts ...Option) *Service {
}
}
func (s *Service) GetRange(ctx context.Context, prm *Prm) (Streamer, error) {
func (s *Service) GetRange(ctx context.Context, prm *Prm) (*Result, error) {
headResult, err := s.headSvc.Head(ctx, new(headsvc.Prm).
WithAddress(prm.addr).
OnlyLocal(prm.local),
@ -83,12 +83,15 @@ func (s *Service) GetRange(ctx context.Context, prm *Prm) (Streamer, error) {
return nil, errors.Wrapf(err, "(%T) could not fill range traverser", s)
}
return &streamer{
return &Result{
head: origin,
stream: &streamer{
cfg: s.cfg,
once: new(sync.Once),
ctx: ctx,
prm: prm,
rangeTraverser: rngTraverser,
},
}, nil
}

View file

@ -35,12 +35,12 @@ func NewService(opts ...Option) *Service {
// GetRange calls internal service and returns v2 object payload range stream.
func (s *Service) GetRange(ctx context.Context, req *objectV2.GetRangeRequest) (objectV2.GetRangeObjectStreamer, error) {
stream, err := s.svc.GetRange(ctx, toPrm(req))
r, err := s.svc.GetRange(ctx, toPrm(req))
if err != nil {
return nil, errors.Wrapf(err, "(%T) could not get object payload range data", s)
}
return fromResponse(stream), nil
return fromResponse(r.Stream()), nil
}
func WithInternalService(v *rangesvc.Service) Option {