Skip to content

Commit

Permalink
Merge pull request #2948 from ipfs/feat/get-progress
Browse files Browse the repository at this point in the history
fix progress bar in ipfs get
  • Loading branch information
whyrusleeping authored Jul 6, 2016
2 parents 2df8dc5 + 43cd49d commit 5d1b28e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions core/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -149,6 +158,7 @@ type getWriter struct {

Archive bool
Compression int
Size int64
}

func (gw *getWriter) Write(r io.Reader, fpath string) error {
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down

0 comments on commit 5d1b28e

Please sign in to comment.