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

Add non-streaming download option to address Payload Incomplete issue #202

Closed
drnextgis opened this issue Jul 22, 2024 · 1 comment · Fixed by #208
Closed

Add non-streaming download option to address Payload Incomplete issue #202

drnextgis opened this issue Jul 22, 2024 · 1 comment · Fixed by #208
Labels
enhancement New feature or request

Comments

@drnextgis
Copy link
Contributor

stac-asset utilizes the Streaming API, but it occasionally encounters the "Response payload is not completed" issue, which the aiohttp team is aware of. Do you think it would be worthwhile to introduce an alternative (non-streaming based) method for downloading assets, even if it means loading them into memory?

stac_asset.errors.DownloadError: ClientPayloadError: Response payload is not completed: <ContentLengthError: 400, message='Not enough data for satisfy content length header.'>
@gadomski
Copy link
Member

Do you think it would be worthwhile to introduce an alternative (non-streaming based) method for downloading assets, even if it means loading them into memory?

I don't see any harm in providing that option ... it'd probably be additional logic in download_href, e.g. an additional argument that would read the entire file into memory instead of iterating over its bytes:

async def download_href(
self,
href: str,
path: PathLikeObject,
clean: bool = True,
content_type: Optional[str] = None,
messages: Optional[MessageQueue] = None,
) -> None:
"""Downloads a file to the local filesystem.
Args:
href: The input href
path: The output file path
clean: If an error occurs, delete the output file if it exists
content_type: The expected content type
messages: An optional queue to use for progress reporting
"""
try:
async with aiofiles.open(path, mode="wb") as f:
async for chunk in self.open_href(
href, content_type=content_type, messages=messages
):
await f.write(chunk)
if messages:
try:
messages.put_nowait(
WriteChunk(href=href, path=Path(path), size=len(chunk))
)
except QueueFull:
pass
except Exception as err:
path_as_path = Path(path)
if clean and path_as_path.exists():
try:
path_as_path.unlink()
except Exception:
pass
raise err

@gadomski gadomski added the enhancement New feature or request label Jul 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants