Take into account resume_len when calculating speed and ETA

This commit is contained in:
Ricardo Garcia 2010-12-15 21:42:11 +01:00
parent b905e5f583
commit 975a91d0ac

View file

@ -617,10 +617,9 @@ class FileDownloader(object):
before = time.time()
data_block = data.read(block_size)
after = time.time()
data_block_len = len(data_block)
if data_block_len == 0:
if len(data_block) == 0:
break
byte_counter += data_block_len
byte_counter += len(data_block)
# Open file just in time
if stream is None:
@ -635,16 +634,16 @@ class FileDownloader(object):
except (IOError, OSError), err:
self.trouble(u'\nERROR: unable to write data: %s' % str(err))
return False
block_size = self.best_block_size(after - before, data_block_len)
block_size = self.best_block_size(after - before, len(data_block))
# Progress message
percent_str = self.calc_percent(byte_counter, data_len)
eta_str = self.calc_eta(start, time.time(), data_len, byte_counter)
speed_str = self.calc_speed(start, time.time(), byte_counter)
eta_str = self.calc_eta(start, time.time(), data_len - resume_len, byte_counter - resume_len)
speed_str = self.calc_speed(start, time.time(), byte_counter - resume_len)
self.report_progress(percent_str, data_len_str, speed_str, eta_str)
# Apply rate limit
self.slow_down(start, byte_counter)
self.slow_down(start, byte_counter - resume_len)
stream.close()
self.report_finish()