mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-28 00:39:31 +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
|
||||
}
|
||||
|
||||
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()
|
||||
|
||||
|
Reference in New Issue
Block a user