fix(util): handle compressed responses in downloadWithProgress (#803) - #945
Open
ousamabenyounes wants to merge 1 commit into
Open
ousamabenyounes wants to merge 1 commit into
ousamabenyounes wants to merge 1 commit into
Conversation
…thProgress For compressed responses (Content-Encoding present) the Content-Length header is the compressed size while the response body reader yields the decompressed bytes. downloadWithProgress compared that compressed total against the decompressed received count, which reported progress above 100% and then threw a bogus "failed to complete download" error before falling back to a plain arrayBuffer read. Detect Content-Encoding and treat the total as unknown (-1) in that case, matching the existing behaviour for responses without a Content-Length. Fixes ffmpegwasm#803
✅ Deploy Preview for ffmpegwasm canceled.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #803.
downloadWithProgress(in@ffmpeg/util) tracks download progress from theContent-Lengthheader. When the server returns a compressed response(
Content-Encoding: gzip/br/…),Content-Lengthis the compressed size,while
fetch's body reader yields the decompressed bytes. The old codecompared that compressed
totalagainst the decompressedreceivedcount, so:received > total(over 100%), andtotal !== receivedthrewERROR_INCOMPLETED_DOWNLOAD, onlymasked by the
arrayBuffer()fallback (the slow path, added in fix: avoid body stream already read on fallback #886).This is exactly the root cause described in the issue.
Fix
Detect the encoding and, when the response carries a
Content-Encodingotherthan
identity, treat the total as unknown (-1) — the same behaviour alreadyused when no
Content-Lengthis present. Comma-separated encodings are handled,and
identity(which means no transformation) keeps the accurate total soprogress still works.
Test verification (RED → GREEN)
Added
tests/util-download-progress.test.js, a Node/mocha test that stubsfetchto return a response whoseContent-Length(compressed) differs fromthe decompressed body the reader delivers. Run it with:
RED — on the unmodified branch (compressed
Content-Length: 100, body of 300 decompressed bytes):GREEN — with the fix:
The suite covers the compressed case (the bug), an uncompressed regression
guard, and
Content-Encoding: identity(total preserved).Scope
Behaviour change is limited to
downloadWithProgress; the public signature ofdownloadWithProgress/toBlobURLis unchanged. Uncompressed responses keeptheir existing accurate progress.