Alexander Chuprov
033eaf77e1
All checks were successful
Build / Build Components (1.20) (pull_request) Successful in 3m52s
Build / Build Components (1.19) (pull_request) Successful in 4m1s
ci/woodpecker/pr/pre-commit Pipeline was successful
Tests and linters / Tests with -race (pull_request) Successful in 5m36s
Tests and linters / Tests (1.20) (pull_request) Successful in 5m55s
Tests and linters / Lint (pull_request) Successful in 14m40s
Tests and linters / Tests (1.19) (pull_request) Successful in 15m29s
ci/woodpecker/push/pre-commit Pipeline was successful
Standardize the alias of the import frostfs-sdk-go/object as objectSDK. Signed-off-by: Alexander Chuprov <a.chuprov@yadro.com>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package getsvc
|
|
|
|
import (
|
|
"context"
|
|
|
|
objectV2 "git.frostfs.info/TrueCloudLab/frostfs-api-go/v2/object"
|
|
objectSvc "git.frostfs.info/TrueCloudLab/frostfs-node/pkg/services/object"
|
|
objectSDK "git.frostfs.info/TrueCloudLab/frostfs-sdk-go/object"
|
|
)
|
|
|
|
type streamObjectWriter struct {
|
|
objectSvc.GetObjectStream
|
|
}
|
|
|
|
type streamObjectRangeWriter struct {
|
|
objectSvc.GetObjectRangeStream
|
|
}
|
|
|
|
func (s *streamObjectWriter) WriteHeader(_ context.Context, obj *objectSDK.Object) error {
|
|
p := new(objectV2.GetObjectPartInit)
|
|
|
|
objV2 := obj.ToV2()
|
|
p.SetObjectID(objV2.GetObjectID())
|
|
p.SetHeader(objV2.GetHeader())
|
|
p.SetSignature(objV2.GetSignature())
|
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
}
|
|
|
|
func (s *streamObjectWriter) WriteChunk(_ context.Context, chunk []byte) error {
|
|
p := new(objectV2.GetObjectPartChunk)
|
|
p.SetChunk(chunk)
|
|
|
|
return s.GetObjectStream.Send(newResponse(p))
|
|
}
|
|
|
|
func newResponse(p objectV2.GetObjectPart) *objectV2.GetResponse {
|
|
r := new(objectV2.GetResponse)
|
|
|
|
body := new(objectV2.GetResponseBody)
|
|
r.SetBody(body)
|
|
|
|
body.SetObjectPart(p)
|
|
|
|
return r
|
|
}
|
|
|
|
func (s *streamObjectRangeWriter) WriteChunk(_ context.Context, chunk []byte) error {
|
|
return s.GetObjectRangeStream.Send(newRangeResponse(chunk))
|
|
}
|
|
|
|
func newRangeResponse(p []byte) *objectV2.GetRangeResponse {
|
|
r := new(objectV2.GetRangeResponse)
|
|
|
|
body := new(objectV2.GetRangeResponseBody)
|
|
r.SetBody(body)
|
|
|
|
part := new(objectV2.GetRangePartChunk)
|
|
part.SetChunk(p)
|
|
|
|
body.SetRangePart(part)
|
|
|
|
return r
|
|
}
|