Skip to content

Instantly share code, notes, and snippets.

@quantum5
Created March 26, 2014 20:36
Show Gist options
  • Save quantum5/9792810 to your computer and use it in GitHub Desktop.
Save quantum5/9792810 to your computer and use it in GitHub Desktop.
import os
def download(file, source, target):
size = int(source.info().getheaders('Content-Length')[0])
print('Downloading {}, Size: {:,d}'.format(file, size))
downloaded = 0
block = 65536
timer = [time.time, time.clock][os.name == 'nt']
start = timer()
while True:
buf = source.read(block)
if not buf:
break
downloaded += len(buf)
target.write(buf)
print '{:15,d} [{:6.2f}%] {:9.2f} kB/s\r'.format(
downloaded, downloaded * 100. / size,
downloaded / 1024. / (timer() - start)),
print '{:15,d} [100.00%]'.format(downloaded)
source.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment