@@ -200,41 +200,43 @@ func (p *Progress) Reset() {
200200}
201201
202202func (p * Progress ) speedStatus (s * Status ) {
203- if p .IncrementalSpeed {
204- lc := s .LinesCompleted - p .prevStatus .LinesCompleted
205- bc := s .BytesCompleted - p .prevStatus .BytesCompleted
206- dc := s .DonePercent - p .prevStatus .DonePercent
207- ela := s .Elapsed - p .prevStatus .Elapsed
208-
209- if lc > 0 {
210- s .SpeedLPS = float64 (lc ) / ela .Seconds ()
211- }
212-
213- if bc > 0 {
214- s .SpeedMBPS = (float64 (bc ) / ela .Seconds ()) / (1024 * 1024 )
215- }
203+ if ! p .IncrementalSpeed {
204+ s .SpeedMBPS = (float64 (s .BytesCompleted ) / s .Elapsed .Seconds ()) / (1024 * 1024 )
205+ s .SpeedLPS = float64 (s .LinesCompleted ) / s .Elapsed .Seconds ()
216206
217207 if s .DonePercent > 0 {
218- s .Remaining = time .Duration ((100.0 - s .DonePercent ) * float64 ( ela ) / dc )
208+ s .Remaining = time .Duration (float64 (100 * s . Elapsed ) / s .DonePercent ) - s . Elapsed
219209 s .Remaining = s .Remaining .Truncate (time .Second )
220210 } else {
221211 s .Remaining = 0
222212 }
223213
224- p .prevStatus = * s
225-
226214 return
227215 }
228216
229- s .SpeedMBPS = (float64 (s .BytesCompleted ) / s .Elapsed .Seconds ()) / (1024 * 1024 )
230- s .SpeedLPS = float64 (s .LinesCompleted ) / s .Elapsed .Seconds ()
217+ lc := s .LinesCompleted - p .prevStatus .LinesCompleted
218+ bc := s .BytesCompleted - p .prevStatus .BytesCompleted
219+ dc := s .DonePercent - p .prevStatus .DonePercent
220+ ela := s .Elapsed - p .prevStatus .Elapsed
231221
232- if s .DonePercent > 0 {
233- s .Remaining = time .Duration (float64 (100 * s .Elapsed )/ s .DonePercent ) - s .Elapsed
222+ if ela != 0 {
223+ if lc > 0 {
224+ s .SpeedLPS = float64 (lc ) / ela .Seconds ()
225+ }
226+
227+ if bc > 0 {
228+ s .SpeedMBPS = (float64 (bc ) / ela .Seconds ()) / (1024 * 1024 )
229+ }
230+ }
231+
232+ if dc > 0 {
233+ s .Remaining = time .Duration ((100.0 - s .DonePercent ) * float64 (ela ) / dc )
234234 s .Remaining = s .Remaining .Truncate (time .Second )
235235 } else {
236236 s .Remaining = 0
237237 }
238+
239+ p .prevStatus = * s
238240}
239241
240242func (p * Progress ) printStatus (last bool ) {
0 commit comments