Fix loading real books: stream downloads to disk #7
Loading…
Reference in a new issue
No description provided.
Delete branch "refs/pull/7/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Loading a real book failed: the device sat on the Downloading screen and then reported "Download failed". The only book ever loaded successfully before was a 21 KB test file, which finished instantly and hid two defects in the Phase 1 download path. The first real book (67 MB) was always going to fail.
Not a progress-sync regression — src/net/ is untouched on that branch and the timeout dates to Phase 1 (
f974d2f).What was wrong
The whole response body was buffered in RAM before a byte reached disk. A 67 MB book meant a 67 MB std::string grown by repeated reallocation, each doubling memcpy-ing tens of megabytes, on a device with little memory to spare.
CURLOPT_TIMEOUT capped the entire transfer, not the connect. A 30 second limit on an unbounded download is wrong by construction: it aborts by design once a book is big enough, no matter how healthy the connection.
The two conspired — the realloc churn dragged the transfer past the cap, and the cap killed it.
What changed
Verification
Host: 55/55 tests pass, clean cross-build. New tests cover the temp-file/rename/cleanup contract, which is the part unit tests can actually reach.
The tests deliberately do not prove the fix — they use a fake transport and so replay whatever shape we believe in. That is the same trap that let two wrong endpoints ship earlier. Real evidence instead:
Honest gap: the original 67 MB book has since been removed from the library, so the precise attribution between the two defects is not reproducible. Both are real and wrong independently.