Skip to content

Commit 2816c98

Browse files
author
dsamaey
committed
Issue #747 robust ranged support (reverted to previous chunking implementation)
1 parent 17243a4 commit 2816c98

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

openeo/rest/job.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import datetime
44
import json
55
import logging
6-
import shutil
76
import time
87
import typing
98
from pathlib import Path
@@ -438,7 +437,8 @@ def _download_ranged(self, url: str, target: Path, file_size: int, *, chunk_size
438437
range_headers = {"Range": f"bytes={from_byte_index}-{to_byte_index}"}
439438
with self.job.connection.get(path=url, headers=range_headers, stream=True) as r:
440439
r.raise_for_status()
441-
shutil.copyfileobj(fsrc=r.raw, fdst=f, length=chunk_size)
440+
for block in r.iter_content(chunk_size=chunk_size):
441+
f.write(block)
442442
break
443443
except OpenEoApiPlainError as error:
444444
tries_left -= 1
@@ -453,7 +453,8 @@ def _download_all_at_once(self, url: str, target: Path, *, chunk_size: int=DEFAU
453453
with self.job.connection.get(path=url, stream=True) as r:
454454
r.raise_for_status()
455455
with target.open("wb") as f:
456-
shutil.copyfileobj(fsrc=r.raw, fdst=f, length=chunk_size)
456+
for block in r.iter_content(chunk_size=chunk_size):
457+
f.write(block)
457458

458459

459460
class MultipleAssetException(OpenEoClientException):

0 commit comments

Comments
 (0)