devopshq / artifactory

dohq-artifactory: a Python client for Artifactory
https://devopshq.github.io/artifactory/
MIT License
273 stars 144 forks source link

fix writeto progress_func: the last chunk #374

Closed gaal-dev closed 2 years ago

gaal-dev commented 2 years ago

Hello.

The last read chunk can be less than chunk_size and the progress won't be reported in this case. My progress bar often stops near 99.7%/99.8%

for chunk in response.iter_content(chunk_size=chunk_size):
  real_chunk += len(chunk)
  if callable(progress_func) and real_chunk - chunk_size >= 0:
     ...
     real_chunk = 0
     ...

So, I added an additional call after the loop.

if real_chunk > 0:
    progress_func(bytes_read + real_chunk, file_size)