diff --git a/darwin/client.py b/darwin/client.py index 0a022b35b..68caaa891 100644 --- a/darwin/client.py +++ b/darwin/client.py @@ -8,7 +8,6 @@ import requests from requests import Response -from requests.packages.urllib3.response import HTTPResponse from darwin.config import Config from darwin.dataset import RemoteDataset @@ -782,7 +781,7 @@ def instantitate_item(self, item_id: int) -> int: return id - def fetch_binary(self, url: str) -> HTTPResponse: + def fetch_binary(self, url: str) -> Response: """ Fetches binary data from the given url via a stream. @@ -793,11 +792,11 @@ def fetch_binary(self, url: str) -> HTTPResponse: Returns ------- - HTTPResponse - The data to be saved. + Response + ``request``'s Response object. """ response: Response = cast(Response, self._get_raw_from_full_url(url, stream=True)) - return response.raw + return response @classmethod def local(cls, team_slug: Optional[str] = None) -> "Client": diff --git a/darwin/dataset/release.py b/darwin/dataset/release.py index b0e98dce2..d4e7750f8 100644 --- a/darwin/dataset/release.py +++ b/darwin/dataset/release.py @@ -1,12 +1,9 @@ import datetime -import shutil from pathlib import Path -from typing import TYPE_CHECKING, Any, Dict, Optional +from typing import Any, Dict, Optional from darwin.dataset.identifier import DatasetIdentifier - -if TYPE_CHECKING: - from darwin.client import Client +from requests import Response class Release: @@ -194,12 +191,15 @@ def download_zip(self, path: Path) -> Path: if not self.url: raise ValueError("Release must have a valid url to download the zip.") + from darwin.client import Client + config_path: Path = Path.home() / ".darwin" / "config.yaml" client: Client = Client.from_config(config_path=config_path, team_slug=self.team_slug) - with client.fetch_binary(self.url) as data: - with open(path, "wb") as download_file: - shutil.copyfileobj(data, download_file) + data: Response = client.fetch_binary(self.url) + with open(path, "wb") as download_file: + for chunk in data.iter_content(chunk_size=8192): + download_file.write(chunk) return path diff --git a/darwin/version/__init__.py b/darwin/version/__init__.py index 894cebca0..fe7c60e81 100644 --- a/darwin/version/__init__.py +++ b/darwin/version/__init__.py @@ -1 +1 @@ -__version__ = "0.7.8" +__version__ = "0.7.9"