Skip to content

Commit 954be39

Browse files
Add additional file size check for ASF S1 bursts downloading
1 parent 1110cc4 commit 954be39

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • insardev_toolkit/insardev_toolkit

insardev_toolkit/insardev_toolkit/ASF.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,7 @@ def download_burst(result, basedir, session):
747747
# Download and validate TIFF entirely in memory before writing to disk
748748
import io
749749

750-
# Download TIFF fully into memory (no streaming — requests will raise
751-
# on incomplete/truncated responses instead of silently returning partial data)
750+
# Download TIFF fully into memory
752751
tiff_url = get_burst_url(properties['url'])
753752
response = session.get(tiff_url, timeout=(10, 300))
754753
response.raise_for_status()
@@ -760,6 +759,16 @@ def download_burst(result, basedir, session):
760759
if len(tiff_bytes) == 0:
761760
raise Exception(f'ERROR: Downloaded TIFF is empty: {tiff_url}')
762761

762+
# Early truncation check using expected size from server or ASF metadata
763+
expected_size = int(response.headers.get('X-Original-Size', 0)) or int(properties['bytes'])
764+
if expected_size > 0 and len(tiff_bytes) < expected_size:
765+
pct = 100 * len(tiff_bytes) / expected_size
766+
cache_status = response.headers.get('x-cache', 'N/A')
767+
raise Exception(f'ERROR: Downloaded TIFF truncated for {burst}: '
768+
f'got {len(tiff_bytes)} bytes ({pct:.0f}%) of {expected_size} expected '
769+
f'(cache: {cache_status}). '
770+
f'The cache proxy may have timed out fetching from upstream.')
771+
763772
# Check if server returned JSON error instead of TIFF
764773
# TIFF magic bytes: II*\x00 (little-endian) or MM\x00* (big-endian)
765774
if tiff_bytes[:2] not in (b'II', b'MM'):

0 commit comments

Comments
 (0)