Fix progress bar reporting incorrect percentage for multi-byte encodings#800
Open
ikatyal2110 wants to merge 1 commit into
Open
Fix progress bar reporting incorrect percentage for multi-byte encodings#800ikatyal2110 wants to merge 1 commit into
ikatyal2110 wants to merge 1 commit into
Conversation
UpdateWrapper tracked progress using len(line) which counts characters, but the progress bar total is set to the file size in bytes. For multi-byte encodings like UTF-16-LE (2 bytes per character) the bar would only reach 50% before the file finished. Now encode each line/chunk back to bytes using the stream's encoding to report the correct byte count.
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.
UpdateWrapper tracked progress using len(line) which counts decoded characters, but the progress bar total is set to the raw file size in bytes. For multi-byte encodings like UTF-16-LE (2 bytes per character) the progress bar would only reach ~50% before the file was fully processed, then stop — looking like a crash. For UTF-32 it would only reach ~25%.
The fix encodes each line/chunk back to bytes using the stream's own encoding attribute to compute the correct byte count before updating the bar. For UTF-8 and ASCII files the behaviour is unchanged since character count equals byte count for the ASCII subset. Regression tests added for both UTF-16-LE and UTF-8 in tests/test_utils.py. Fixes #439
Generated by Claude Code
📚 Documentation preview 📚: https://sqlite-utils--800.org.readthedocs.build/en/800/