diff --git a/pyvo/utils/download.py b/pyvo/utils/download.py index e14be3f69..450256f09 100644 --- a/pyvo/utils/download.py +++ b/pyvo/utils/download.py @@ -69,7 +69,9 @@ def http_download(url, length = None if cache and os.path.exists(local_filepath): - local_size = os.stat(local_filepath).st_size + with open(local_filepath, 'rb'): + fp.seek(0, os.SEEK_END) + local_size = fp.tell() if length is not None and local_size != length: warn('Found cached file but it has the wrong size. Overwriting ...', category=PyvoUserWarning) @@ -234,8 +236,10 @@ def aws_download(uri=None, if cache and os.path.exists(local_filepath): if length is not None: - statinfo = os.stat(local_filepath) - if statinfo.st_size == length: + with open(local_filepath, 'rb'): + fp.seek(0, os.SEEK_END) + local_size = fp.tell() + if local_size == length: # found cached file with expected size. Stop if verbose: print(f'Found cached file {local_filepath}.')