Correctly report downloaded file size in debug messages.
Previously, the return value of fp.write() was used, however for text files this counts the number of characters written, not the number of bytes, and for non-ASCII content these differ.
This commit is contained in:
parent
9970f21e47
commit
0a9846b342
6
av98.py
6
av98.py
|
@ -649,6 +649,7 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
else:
|
||||
print("{} Received {} MiB...".format(spinner, chunk_count/10.0), end="\r")
|
||||
print(" "*80, end="\r") # Clean up prompt space
|
||||
size = len(body)
|
||||
|
||||
# Determine file mode
|
||||
if mime.startswith("text/"):
|
||||
|
@ -666,9 +667,8 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
encoding = None
|
||||
|
||||
# Write
|
||||
fp = open(destination or self.raw_file_buffer, mode=mode, encoding=encoding)
|
||||
size = fp.write(body)
|
||||
fp.close()
|
||||
with open(destination or self.raw_file_buffer, mode=mode, encoding=encoding) as fp:
|
||||
fp.write(body)
|
||||
|
||||
return size
|
||||
|
||||
|
|
Loading…
Reference in New Issue