def _chunked_url_copier(src, dst, reporthook, chunk_size, aborthook): aborthook = aborthook if aborthook is not None else lambda: False total_size = int(src.info().get('Content-Length').strip( )) if src.info() and src.info().get('Content-Length') else 0 total_chunks = 0 while not aborthook(): reporthook(total_chunks, chunk_size, total_size) byteStringchunk = src.read(chunk_size) if not byteStringchunk: # operation has finished return dst.write(bytearray(byteStringchunk)) total_chunks += 1 # abort requested raise ExitRequested('Reception interrupted.')
def _chunked_url_copier(u, f, reporthook, chunk_size, aborthook): aborthook = aborthook if aborthook is not None else lambda: False total_size = int(u.info().getheader('Content-Length').strip( )) if u.info() and u.info().getheader('Content-Length') else 0 total_chunks = 0 while not aborthook(): reporthook(total_chunks, chunk_size, total_size) chunk = u.read(chunk_size) if not chunk: # operation has finished return f.write(chunk) total_chunks += 1 # abort requested raise ExitRequested('Reception interrupted.')