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

download using chunk iteration rather than raw response #920

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html)

## [Unreleased]

### Fixed

- `earthaccess.download` will let requests automatically decode compressed content
([#887](https://github.com/nsidc/earthaccess/issues/887))
([**@itcarroll**](https://github.com/itcarroll))

## [v0.12.0] - 2024-11-13

### Changed
Expand Down
12 changes: 4 additions & 8 deletions earthaccess/store.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import logging
import shutil
import traceback
from functools import lru_cache
from itertools import chain
Expand Down Expand Up @@ -670,16 +669,13 @@ def _download_file(self, url: str, directory: Path) -> str:
if not path.exists():
try:
session = self.auth.get_session()
with session.get(
url,
stream=True,
allow_redirects=True,
) as r:
with session.get(url, stream=True, allow_redirects=True) as r:
r.raise_for_status()
with open(path, "wb") as f:
# This is to cap memory usage for large files at 1MB per write to disk per thread
# Cap memory usage for large files at 1MB per write to disk per thread
# https://docs.python-requests.org/en/latest/user/quickstart/#raw-response-content
shutil.copyfileobj(r.raw, f, length=1024 * 1024)
for chunk in r.iter_content(chunk_size=1024 * 1024):
f.write(chunk)
except Exception:
logger.exception(f"Error while downloading the file {local_filename}")
raise Exception
Expand Down
Loading