解压非utf8编码,如cp949、sjis、gbk、euc kr、euc jp和gb2312
unzipmbcs的Python项目详细描述
提取mbcs(多字节字符集)编码文件的zip文件 名称,如在MS Windows中创建的ZIP文件,尤其是东亚 环境。
按语言分类的主要非utf8编码:*韩语:cp949,euc-kr* 日语:sjis(shift_jis),cp932,euc-jp*中文:gbk,gb8030, GB2312、CP936、香港特别行政区、第五大城市、CP950
安装
pip install unzipmbcs
cli用法
usage: unzipmbcs [-h] [-e ENCODING] cmd zipfile [target [target ...]] unzip for non-UTF8 filenames in zip archive positional arguments: cmd commands: l(list), x(extract) zipfile .zip file to unzip target file prefix to extract optional arguments: -h, --help show this help message and exit -e ENCODING, --encoding ENCODING character encoding of filename in the .zip
API
listzip(文件名,encoding='utf-8')
用返回zip存档文件filename中的文件信息 字符encoding
extractzip(文件名,encoding='utf-8',filters=none)
在当前目录的zip存档文件filename中提取文件。假设 zip归档文件中的文件名编码为encoding。只有 前缀为filterslist的值的文件将被提取,如果 filters已提供。
fixzipfilename(文件名,enc)
将filename修复为最初编码为 enc。适用于Python2和3。
动机
.zip格式pkzip压缩已经被广泛使用。一些有价值的 数据存档为.zip文件。但是,非ascii,非西方 在环境中,它会因文件名而产生问题。
由于ZIP格式创建得太旧(1993),因此没有标准 压缩存档项文件名的字符编码。大部分 zip文件条目编码为传统字符编码,本地 字符集。
在现代基于unicode的环境或全局数据处理中 像Linux这样的环境,这使得不方便性、可移植性降低, 文件名损坏,无法提取文件,等等。
这个模块可以减轻不公正。