修改自网络上解决linux下解压gbk编码zip文件乱码的python方案
opensuse吧
全部回复
仅看楼主
level 10
原问题:https://www.zhihu.com/question/20523036
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import zipfile
print "Processing File " + sys.argv[1]
if len(sys.argv) > 2:
passwdstr = sys.argv[2];
if not len(sys.argv) > 2:
passwdstr = None;
file=zipfile.ZipFile(sys.argv[1],"r");
for name in file.namelist():
utf8name=name.decode('gbk')
print "Extracting " + utf8name
pathname = os.path.dirname(utf8name)
if not os.path.exists(pathname) and pathname!= "":
os.makedirs(pathname)
file.setpassword(passwdstr)
data = file.read(name)
if not os.path.exists(utf8name):
fo = open(utf8name, "w")
fo.write(data)
fo.close
file.close()
运行这个程序传入两个参数,第一个是文件的路径,第二个是可选参数,为文件解压密码
目前的问题是python自带的zip模块解压效率太低,日后再进行研究
2016年12月27日 08点12分 1
level 11
你写好了没,我昨天试了一把,最后发现似乎由于zip算法的原因,根本没法并发读写,勉强写出个类似全局锁下的多线程,性能大部分情况比单线程差,比unzip强一点,比7z弱不少。
所以说最好的方法似乎是自己去魔改下7z,改一下文件名那一块就行了,就不用费心想各种性能,各种密码,修复等等[阴险]
2017年02月18日 12点02分 3
咕咕
2017年02月18日 12点02分
回复
天降の情兽
:咕咕
2017年02月18日 13点02分
level 11
Unzip with charset setting简单的实现了,223,[咦]
https://github.com/biluohc/zipcs
2017年02月19日 14点02分 6
强![大拇指] 这个好啊
2017年02月19日 18点02分
1