Skip to content

feat: encoding auto-detection for non-UTF-8 archives - #44

Open
alex3236 wants to merge 2 commits into
AkiZip:masterfrom
alex3236:encoding-detection
Open

feat: encoding auto-detection for non-UTF-8 archives#44
alex3236 wants to merge 2 commits into
AkiZip:masterfrom
alex3236:encoding-detection

Conversation

@alex3236

@alex3236 alex3236 commented Jun 7, 2026

Copy link
Copy Markdown

ZIP archives store filenames using the system-local encoding of the OS where they were created, with no explicit encoding marker in the original format. The PKZip APPNOTE later introduced a "language encoding flag" (bit 11): when set to 1, filenames should be UTF-8; when 0, they use the local encoding. In practice, however, many implementations set the flag to 1 (because they "know" the filename is not plain ASCII) but still write the actual bytes in the local encoding — GBK, Shift-JIS, Big5, etc. This means the flag alone is not reliable for detecting encoding.

Previously 7zz output was decoded as UTF-8, so non-UTF-8 filenames would show as garbled text in the GUI. This PR detects the correct encoding before displaying the listing.

The detection flow works as follows:

  • archive_list() captures raw bytes from 7zz (switched from text=True to binary mode)
  • The output is passed to _decode_7zip_output(), which first tries chardet (if available) and falls back to a heuristic scorer
  • The heuristic decodes the data with each candidate encoding (GBK, Shift-JIS, Big5, EUC-KR, CP1251) and scores based on Unicode character range patterns — e.g., GBK produces CJK ideographs, Shift-JIS contains hiragana/katakana, CP1251 produces Cyrillic letters, and so on
  • The detected encoding is cached per archive path for the session
  • On extraction, -mcp= is passed to 7zz so filenames are written correctly to disk
  • python3-chardet added to Flatpak manifest

alex3236 added 2 commits June 7, 2026 16:48
- Use chardet (fallback to heuristic) to detect filename encoding
- Switch _run_7zip from text=True to binary mode for raw bytes
- Cache detected encoding per archive; pass -mcp to 7zz on extraction
- Add python3-chardet to Flatpak manifest
- Handle GBK, Shift-JIS, Big5, EUC-KR, CP1251 archives
Flatpak-builder sandbox has no network access, so pip3 install from PyPI
fails with DNS resolution errors. Bundle the wheel as a local source
instead.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants