download progress

This commit is contained in:
j 2014-05-25 16:21:00 +02:00
parent 9a6278bb83
commit eac91e7a3a

View file

@ -306,11 +306,13 @@ class Node(Thread):
if r.headers.get('content-encoding', None) == 'gzip': if r.headers.get('content-encoding', None) == 'gzip':
content = gzip.GzipFile(fileobj=r).read() content = gzip.GzipFile(fileobj=r).read()
else: else:
'''
content = '' content = ''
for chunk in iter(lambda: r.read(1024*1024), ''): ct = datetime.utcnow()
t = Transfer.get(item.id) for chunk in iter(lambda: r.read(16*1024), ''):
content += chunk content += chunk
if (datetime.utcnow() - ct).total_seconds() > 1:
ct = datetime.utcnow()
t = Transfer.get(item.id)
t.progress = len(content) / item.info['size'] t.progress = len(content) / item.info['size']
t.save() t.save()
trigger_event('transfer', { trigger_event('transfer', {
@ -318,6 +320,7 @@ class Node(Thread):
}) })
''' '''
content = r.read() content = r.read()
'''
t2 = datetime.utcnow() t2 = datetime.utcnow()
duration = (t2-t1).total_seconds() duration = (t2-t1).total_seconds()