From 0c3ea6976717d8fc692710e303a87bce1428da04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simen=20Heggest=C3=B8yl?= Date: Wed, 3 Sep 2025 14:43:58 +0200 Subject: [PATCH] Fix binary downloads --- CHANGELOG.md | 1 + okdata/sdk/data/download.py | 4 ++-- okdata/sdk/io_utils.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c37bed5..a7e4038 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## ?.?.? - Unreleased +* Fixed binary file downloads. * Fixed credentials cache handling. ## 3.3.0 - 2025-06-20 diff --git a/okdata/sdk/data/download.py b/okdata/sdk/data/download.py index 093f17b..5dc8662 100644 --- a/okdata/sdk/data/download.py +++ b/okdata/sdk/data/download.py @@ -28,10 +28,10 @@ def download(self, dataset_id, version, edition, output_path, retries=0): downloaded_files = [] for file in self.get_files(dataset_id, version, edition, retries=retries): file_name = file["key"].split("/")[-1] - file_content_response = requests.get(file["url"]) + file_content_response = requests.get(file["url"], stream=True) file_content_response.raise_for_status() - write_file_content(file_name, output_path, file_content_response.text) + write_file_content(file_name, output_path, file_content_response.raw.read()) downloaded_files.append(f"{output_path}/{file_name}") return {"files": downloaded_files} diff --git a/okdata/sdk/io_utils.py b/okdata/sdk/io_utils.py index 9797228..e12e725 100644 --- a/okdata/sdk/io_utils.py +++ b/okdata/sdk/io_utils.py @@ -42,5 +42,5 @@ def write_file_content(file_name, path, content): if not Path(path).exists(): create_dir(path) - with open(f"{path}/{file_name}", "w+") as file: + with open(f"{path}/{file_name}", "wb") as file: file.write(content)