Provider progress animation when downloading files > 100 KiB.

This commit is contained in:
Solderpunk 2023-11-15 19:46:01 +01:00
parent f78b6ff780
commit 50c43c75b4
1 changed files with 15 additions and 1 deletions

16
av98.py
View File

@ -645,8 +645,22 @@ Slow internet connection? Use 'set timeout' to be more patient.""")
return status, meta, address, f
def _write_response_to_file(self, mime, mime_options, f, destination):
spinner_seq = ["|", "/", "-", "\\"]
# Read the response body over the network
body = f.read()
body = bytearray([])
chunk_count = 0
while True:
chunk = f.read(100*1024)
chunk_count += 1
if not chunk:
break
body.extend(chunk)
if chunk_count > 1:
spinner = spinner_seq[chunk_count % 4]
if chunk_count < 10:
print("{} Received {} KiB...".format(spinner, chunk_count*100), end="\r")
else:
print("{} Received {} MiB...".format(spinner, chunk_count/10.0), end="\r")
# Save the result to a temporary file