Skip to content

Commit fd28177

Browse files
authored
fix: support for compressed content in download2stream method. (#353)
Fixes #352 . By switching from `iter_raw` to `iter_bytes`, **httpx will automatically handle the decompression** if the `Content-Encoding: gzip` header is present. If the header is absent or specifies no compression (like identity), `iter_bytes` will yield the original bytes, just like `iter_raw` would have. Signed-off-by: bigcat88 <[email protected]>
1 parent 57c6d34 commit fd28177

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [0.19.3 - 2025-04-28]
6+
7+
### Fixed
8+
9+
- Method `download2stream` not working correctly when Nextcloud returns compressed content. #352 Thanks to @PatrickPromitzer for reporting this.
10+
511
## [0.19.2 - 2025-03-17]
612

713
### Added

nc_py_api/_session.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def download2fp(self, url_path: str, fp, dav: bool, params=None, **kwargs):
307307
adapter = self.adapter_dav if dav else self.adapter
308308
with adapter.stream("GET", url_path, params=params, headers=kwargs.get("headers")) as response:
309309
check_error(response)
310-
for data_chunk in response.iter_raw(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
310+
for data_chunk in response.iter_bytes(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
311311
fp.write(data_chunk)
312312

313313

@@ -434,7 +434,7 @@ async def download2fp(self, url_path: str, fp, dav: bool, params=None, **kwargs)
434434
adapter = self.adapter_dav if dav else self.adapter
435435
async with adapter.stream("GET", url_path, params=params, headers=kwargs.get("headers")) as response:
436436
check_error(response)
437-
async for data_chunk in response.aiter_raw(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
437+
async for data_chunk in response.aiter_bytes(chunk_size=kwargs.get("chunk_size", 5 * 1024 * 1024)):
438438
fp.write(data_chunk)
439439

440440

0 commit comments

Comments
 (0)