forked from TrueCloudLab/frostfs-node
[#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:
parent
b68778ea90
commit
e42b7f6a65
2 changed files with 15 additions and 1 deletions
|
@ -299,6 +299,8 @@ type PutObjectPrm struct {
|
||||||
hdr *object.Object
|
hdr *object.Object
|
||||||
|
|
||||||
rdr io.Reader
|
rdr io.Reader
|
||||||
|
|
||||||
|
headerCallback func(*object.Object)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetHeader sets object header.
|
// SetHeader sets object header.
|
||||||
|
@ -311,6 +313,12 @@ func (x *PutObjectPrm) SetPayloadReader(rdr io.Reader) {
|
||||||
x.rdr = rdr
|
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.
|
// PutObjectRes groups the resulting values of PutObject operation.
|
||||||
type PutObjectRes struct {
|
type PutObjectRes struct {
|
||||||
id oid.ID
|
id oid.ID
|
||||||
|
@ -347,6 +355,10 @@ func PutObject(prm PutObjectPrm) (*PutObjectRes, error) {
|
||||||
wrt.WithXHeaders(prm.xHeaders...)
|
wrt.WithXHeaders(prm.xHeaders...)
|
||||||
|
|
||||||
if wrt.WriteHeader(*prm.hdr) {
|
if wrt.WriteHeader(*prm.hdr) {
|
||||||
|
if prm.headerCallback != nil {
|
||||||
|
prm.headerCallback(prm.hdr)
|
||||||
|
}
|
||||||
|
|
||||||
sz := prm.hdr.PayloadSize()
|
sz := prm.hdr.PayloadSize()
|
||||||
|
|
||||||
if data := prm.hdr.Payload(); len(data) > 0 {
|
if data := prm.hdr.Payload(); len(data) > 0 {
|
||||||
|
|
|
@ -128,7 +128,9 @@ func putObject(cmd *cobra.Command, _ []string) {
|
||||||
p = pb.New64(fi.Size())
|
p = pb.New64(fi.Size())
|
||||||
p.Output = cmd.OutOrStdout()
|
p.Output = cmd.OutOrStdout()
|
||||||
prm.SetPayloadReader(p.NewProxyReader(f))
|
prm.SetPayloadReader(p.NewProxyReader(f))
|
||||||
p.Start()
|
prm.SetHeaderCallback(func(o *object.Object) {
|
||||||
|
p.Start()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue