Skip to content

Commit

Permalink
Download file locally when range request not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
albertvillanova committed Feb 8, 2022
1 parent 72cacbe commit 9f90bcb
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/datasets/utils/streaming_download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,15 @@ def xopen(file: str, mode="r", *args, use_auth_token: Optional[Union[str, bool]]
else:
new_kwargs = {}
kwargs = {**kwargs, **new_kwargs}
file_obj = fsspec.open(file, mode=mode, *args, **kwargs).open()
try:
file_obj = fsspec.open(file, mode=mode, *args, **kwargs).open()
except ValueError as e:
if str(e) == "Cannot seek streaming HTTP file": # Workaround for servers not supporting HTTP range requests
file = file.split("::")
file = "::".join(file[:-1] + ["simplecache", file[-1]])
file_obj = fsspec.open(file, mode=mode, *args, **kwargs).open()
else:
raise
_add_retries_to_file_obj_read_method(file_obj)
return file_obj

Expand Down

0 comments on commit 9f90bcb

Please sign in to comment.