Skip to content

Support overriding metadata_encoding#38

Draft
SadPencil wants to merge 1 commit intodanifus:masterfrom
SadPencil:feat-encoding
Draft

Support overriding metadata_encoding#38
SadPencil wants to merge 1 commit intodanifus:masterfrom
SadPencil:feat-encoding

Conversation

@SadPencil
Copy link

@SadPencil SadPencil commented Apr 18, 2025

This PR tries to bring the metadata_encoding support that was introduced in Python 3.11.

https://docs.python.org/3.11/library/zipfile.html

metadata_encoding is an instance-wide setting for the ZipFile. It is not currently possible to set this on a per-member basis.

This attribute is a workaround for legacy implementations which produce archives with names in the current locale encoding or code page (mostly on Windows). According to the .ZIP standard, the encoding of metadata may be specified to be either IBM code page (default) or UTF-8 by a flag in the archive header. That flag takes precedence over metadata_encoding, which is a Python-specific extension.

import pyzipper

with pyzipper.AESZipFile(zip_file, metadata_encoding='gbk') as zf:
    zf.extractall(path=extract_dir, pwd=password)

On my machine it works. But I have not fully tested the code so I'll mark this PR as a draft.

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.

1 participant