refactor(downloader): extract _stream_to_file() helper

Eliminate the ~30-line duplicated chunked-download loop across
download_m4b(), download_zip_part(), _download_cover(), and
_download_pdf() by extracting a shared _stream_to_file() private
helper. Each caller is now a thin wrapper that delegates streaming
to the helper then performs its own post-processing step.

5 new TDD tests covering fresh download, resume, cancel mid-stream,
progress callback with content-length, and HTTP error propagation.
224 total tests pass. Net -22 lines in downloader.py.

Closes #41
This commit is contained in:
AlexKucera committed 2026-06-05 19:05:23 +02:00
1 parent d55fa9acbb
commit fcdba333d1
5 files changed
+349 -117

No files matched your search

+8
View File
@@ -40,6 +40,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`session._client._transport` to `session.transport`. 2 new tests, 425 total.
Closes #38.
- **downloader:** Extract `_stream_to_file()` private helper from the
duplicated ~30-line chunked-download loop in `download_m4b()`,
`download_zip_part()`, `_download_cover()`, and `_download_pdf()`. All
four callers are now thin wrappers that delegate streaming to the
shared helper. 5 new TDD tests (fresh download, resume, cancel
mid-stream, progress callback, error propagation). 224 total tests.
Net -22 lines in downloader.py. Closes #41.
- **session:** Rename LibroFmClient → LibroFmSession, relocate to
session.py, inject transport at construction time. Old client.py is now