Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix streaming for servers not supporting HTTP range requests #3689

Merged
merged 3 commits into from
Feb 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/datasets/utils/streaming_download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
)


class NonStreamableDatasetError(Exception):
pass


def xjoin(a, *p):
"""
This function extends os.path.join to support the "::" hop separator. It supports both paths and urls.
Expand Down Expand Up @@ -383,7 +387,16 @@ 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":
raise NonStreamableDatasetError(
"Streaming is not possible for this dataset because data host server doesn't support HTTP range "
"requests. You can still load this dataset in non-streaming mode by passing `streaming=False` (default)"
) from e
else:
raise
_add_retries_to_file_obj_read_method(file_obj)
return file_obj

Expand Down