mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +08:00
Merge pull request #2948 from ipfs/feat/get-progress
fix progress bar in ipfs get
This commit is contained in:
@ -69,6 +69,14 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size, err := dn.Size()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmds.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res.SetLength(size)
|
||||||
|
|
||||||
archive, _, _ := req.Option("archive").Bool()
|
archive, _, _ := req.Option("archive").Bool()
|
||||||
reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl)
|
reader, err := uarchive.DagArchive(ctx, dn, p.String(), node.DAG, archive, cmplvl)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -103,6 +111,7 @@ may also specify the level of compression by specifying '-l=<1-9>'.
|
|||||||
Err: os.Stderr,
|
Err: os.Stderr,
|
||||||
Archive: archive,
|
Archive: archive,
|
||||||
Compression: cmplvl,
|
Compression: cmplvl,
|
||||||
|
Size: int64(res.Length()),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gw.Write(outReader, outPath); err != nil {
|
if err := gw.Write(outReader, outPath); err != nil {
|
||||||
@ -149,6 +158,7 @@ type getWriter struct {
|
|||||||
|
|
||||||
Archive bool
|
Archive bool
|
||||||
Compression int
|
Compression int
|
||||||
|
Size int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gw *getWriter) Write(r io.Reader, fpath string) error {
|
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()
|
defer file.Close()
|
||||||
|
|
||||||
fmt.Fprintf(gw.Out, "Saving archive to %s\n", fpath)
|
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()
|
bar.Start()
|
||||||
defer bar.Finish()
|
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 {
|
func (gw *getWriter) writeExtracted(r io.Reader, fpath string) error {
|
||||||
fmt.Fprintf(gw.Out, "Saving file(s) to %s\n", fpath)
|
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()
|
bar.Start()
|
||||||
defer bar.Finish()
|
defer bar.Finish()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user