Skip to content

Fix progress bar reporting incorrect percentage for multi-byte encodings#800

Open
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-progress-bar-multibyte-encoding
Open

Fix progress bar reporting incorrect percentage for multi-byte encodings#800
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-progress-bar-multibyte-encoding

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Jul 15, 2026

Copy link
Copy Markdown

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/

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading progress bar against utf-16-le CSV input

1 participant