1

Im trying to Build a downloader application and i need help with request library here.

while total_bytes != n_bytes_read:

    header = {"Range": "bytes={}-{}".format(n_bytes_read, total_bytes+1 )}

    r = requests.get(self.url, headers=header,stream = True, timeout=(10,10))

    for chunk in r.iter_content(chunk_size=chunk_size):
        if  (len(chunk) == chunk_size) or (n_bytes_read + len(chunk) == total_bytes):
            f.write(chunk)
            n_bytes_read += len(chunk)
            chunk_size *= 2
            update_progress_bar(n_bytes_read)
        else
            chunk_size = int(chunk_size / 2)

Im trying to speed up the download process but this part seems to hinder that

Charan Sai
  • 13
  • 5
  • Once you have created the iterator by `r.iter_content(chunk_size=chunk_size)`. You can't change its size. – Dan D. Jan 22 '19 at 11:35
  • So theres no other way to make the chunk_size more flexible throughout the download loop?? – Charan Sai Jan 22 '19 at 15:09
  • You can't use a variable before it's declared. In `chunk_size=chunk_size`, the value of `chunk_size` hasn't been declared yet when the interpreter gets to that point, so your code doesn't even work. – Dustin Wyatt Sep 09 '20 at 03:50

0 Answers0