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 #375

Closed gaal-dev closed 2 years ago

gaal-dev commented 2 years ago

Hello. My progree bar often stops at 99.7% or 99.8% because the last chunk can be smaller than chunk_size

        bytes_read = 0
        real_chunk = 0
        for chunk in response.iter_content(chunk_size=chunk_size):
            real_chunk += len(chunk)
            if callable(progress_func) and real_chunk - chunk_size >= 0:
                # Artifactory archives folders on fly and can reduce requested chunk size to 8kB, thus report
                # only when real chunk size met
                bytes_read += real_chunk
                real_chunk = 0
                progress_func(bytes_read, file_size)

            file.write(chunk)

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