diff --git a/core/commands/get.go b/core/commands/get.go index 1835371af45..16b8cf91299 100644 --- a/core/commands/get.go +++ b/core/commands/get.go @@ -69,6 +69,14 @@ may also specify the level of compression by specifying '-l=<1-9>'. return } + size, err := dn.Size() + if err != nil { + res.SetError(err, cmds.ErrNormal) + return + } + + res.SetLength(size) + archive, _, _ := req.Option("archive").Bool() reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl) if err != nil { @@ -103,6 +111,7 @@ may also specify the level of compression by specifying '-l=<1-9>'. Err: os.Stderr, Archive: archive, Compression: cmplvl, + Size: int64(res.Length()), } if err := gw.Write(outReader, outPath); err != nil { @@ -149,6 +158,7 @@ type getWriter struct { Archive bool Compression int + Size int64 } func (gw *getWriter) Write(r io.Reader, fpath string) error { @@ -181,7 +191,7 @@ func (gw *getWriter) writeArchive(r io.Reader, fpath string) error { defer file.Close() fmt.Fprintf(gw.Out, "Saving archive to %s\n", fpath) - bar, barR := progressBarForReader(gw.Err, r, 0) + bar, barR := progressBarForReader(gw.Err, r, gw.Size) bar.Start() defer bar.Finish() @@ -191,7 +201,7 @@ func (gw *getWriter) writeArchive(r io.Reader, fpath string) error { func (gw *getWriter) writeExtracted(r io.Reader, fpath string) error { fmt.Fprintf(gw.Out, "Saving file(s) to %s\n", fpath) - bar, barR := progressBarForReader(gw.Err, r, 0) + bar, barR := progressBarForReader(gw.Err, r, gw.Size) bar.Start() defer bar.Finish()