[#1484] neofs-cli: Print progress bar after the header has been sent

Make it similar to `object get`.

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-06-08 10:55:52 +03:00 committed by fyrchik
parent b68778ea90
commit e42b7f6a65
2 changed files with 15 additions and 1 deletions

View file

@ -299,6 +299,8 @@ type PutObjectPrm struct {
hdr *object.Object
rdr io.Reader
headerCallback func(*object.Object)
}
// SetHeader sets object header.
@ -311,6 +313,12 @@ func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) {
x.rdr = rdr
}
// SetHeaderCallback sets callback which is called on the object after the header is received
// but before the payload is written.
func (x *PutObjectPrm) SetHeaderCallback(f func(*object.Object)) {
x.headerCallback = f
}
// PutObjectRes groups the resulting values of PutObject operation.
type PutObjectRes struct {
id oid.ID
@ -347,6 +355,10 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
wrt.WithXHeaders(prm.xHeaders...)
if wrt.WriteHeader(*prm.hdr) {
if prm.headerCallback != nil {
prm.headerCallback(prm.hdr)
}
sz := prm.hdr.PayloadSize()
if data := prm.hdr.Payload(); len(data) > 0 {

View file

@ -128,7 +128,9 @@ func putObject(cmd *cobra.Command, _ []string) {
p = pb.New64(fi.Size())
p.Output = cmd.OutOrStdout()
prm.SetPayloadReader(p.NewProxyReader(f))
prm.SetHeaderCallback(func(o *object.Object) {
p.Start()
})
}
}