-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Fix progress reporting for compressed downloads in fetchRemotePackage #24144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix progress reporting for compressed downloads in fetchRemotePackage #24144
Conversation
tools/file_packager.py
Outdated
if (isCompressed) { | ||
// Estimate progress proportionally, assuming 3:1 compression ration | ||
loaded = Math.min(total, | ||
total * (decompressedLoaded / (packageSize || total * 3))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems a little too much like guesswork. Is there really no better way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sbc100 how about now?
8d30366
to
0a9dfbf
Compare
0a9dfbf
to
290785d
Compare
Can you update the PR description and title now that we have changed the PR content? |
Do you know why we cannot just use |
just my guess, |
When a server uses compression (e.g., Brotli (
br
) or Gzip (gzip
)), theContent-Length
header in the HTTP response represents the compressed size of the data, not the uncompressed size. ThefetchRemotePackage
function, however, tracks the uncompressed size of the downloaded data (via value.length of each chunk after decompression). This leads to a discrepancy where the reportedtotalLoaded
(uncompressed) exceeds the Content-Length (compressed), causing inaccurate progress reporting.The Fetch API does not provide direct access to the compressed stream’s size for each chunk, as decompression is handled transparently. The updated code addresses this by aligning the total and loaded values with the compressed size from Content-Length when the content is compressed. Specifically:
This ensures progress reporting reflects the compressed size, preventing totalLoaded from exceeding total.