Skip to content

Fix progress bar stalling at ~50% for multi-byte encodings (e.g. utf-16-le)#812

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

Fix progress bar stalling at ~50% for multi-byte encodings (e.g. utf-16-le)#812
ikatyal2110 wants to merge 1 commit into
simonw:mainfrom
ikatyal2110:fix-utf16-progress-bar

Conversation

@ikatyal2110

@ikatyal2110 ikatyal2110 commented Jul 24, 2026

Copy link
Copy Markdown

When inserting a CSV file with a multi-byte encoding like utf-16-le, the progress bar would stall at around 50% and then jump to done at the end. This happened because UpdateWrapper.__iter__ tracked progress using len(line) (character count), but the bar is initialised with os.path.getsize() (byte count) — for utf-16-le each character is 2 bytes, so the reported progress was always half the real value.

The fix uses TextIOWrapper.buffer.tell() to read the underlying binary stream position (actual bytes consumed) when available, falling back to len(line) for non-TextIOWrapper objects so existing behaviour is unchanged.

Fixes #439


Generated by Claude Code


📚 Documentation preview 📚: https://sqlite-utils--812.org.readthedocs.build/en/812/

…6-le

UpdateWrapper.__iter__ was using len(line) (character count) to track
progress, but the progress bar is initialised with os.path.getsize()
(byte count).  For utf-16-le each character is 2 bytes, so the bar
only ever reached ~50% before the insert completed.

Use TextIOWrapper.buffer.tell() when available to report the true
number of bytes consumed, falling back to len(line) for non-TextIOWrapper
objects.

Fixes simonw#439
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

2 participants