我正在尝试提取zip文件的内容,可在此处查看:
https://www.geoboundaries.org/data/geoBoundaries-2_0_0/NGA/ADM1/geoBoundaries-2_0_0-NGA-ADM1-all.zip
在Ubuntu18.04.04上,通过右键单击菜单中的“提取”选项,我从zip文件中获得了一个文件夹结构,其中包括各种空文件夹和目录,以及不同的父文件夹。如果我使用7Zip(在windows或相同的linux设备上)解压相同的文件,我将得到6个文件的预期结果
那么-这里有什么区别
(注意,我已经有了一个解决方案——shutil archive works——只是试图理解不同的行为)
这是当前用于构建相关ZIP的代码(python):
def zipdir(dirPath=None, zipFilePath=None, includeDirInZip=False, citeUsePath=False):
if not zipFilePath:
zipFilePath = dirPath + ".zip"
if not os.path.isdir(dirPath):
raise OSError("dirPath argument must point to a directory. "
"'%s' does not." % dirPath)
parentDir, dirToZip = os.path.split(dirPath)
def trimPath(path):
archivePath = path.replace(parentDir, "", 1)
if parentDir:
archivePath = archivePath.replace(os.path.sep, "", 1)
if not includeDirInZip:
archivePath = archivePath.replace(dirToZip + os.path.sep, "", 1)
return os.path.normcase(archivePath)
outFile = zipfile.ZipFile(zipFilePath, "w",compression=zipfile.ZIP_DEFLATED)
for (archiveDirPath, dirNames, fileNames) in os.walk(dirPath):
for fileName in fileNames:
if(not fileName == zipFilePath.split("/")[-1]):
filePath = os.path.join(archiveDirPath, fileName)
outFile.write(filePath, trimPath(filePath))
outFile.write(citeUsePath, os.path.basename(citeUsePath))
outFile.close()
zip文件
geoBoundaries-2_0_0-NGA-ADM1-all.zip
是非标准文件在Linux上,
unzip
认为有5个文件没有路径组件如果我尝试提取内容,我会收到很多警告
分析
zip文件中每个条目的详细信息(包括文件名)存储两次。一次在压缩数据前面的
local-header
中,另一次在文件末尾的central-header
中。因此,对于存储在zip文件中的每个文件,都会有一对local-header
/central-header
字段。这些字段对中的数据应该(大部分)相同在这种情况下,它们不是
例如,考虑^ {< CD4>}条目为{{CD8}}。匹配的
local-header
具有release/geoBoundaries-2_0_0/NGA/ADM1/geoBoundaries-2_0_0-NGA-ADM1-shp.zip
此zip文件中的所有条目也是如此
鉴于这是一个非标准/无效的zip文件,解压缩时的行为将取决于解压缩实用程序是使用
central-header
项中的数据来确定文件名,还是使用local-header
项中的等效数据看起来Ubuntu使用的是
local-header
字段,而7zip使用的是central-header
字段作为参考,zip文件的规范为APPNOTE.TXT
相关问题 更多 >
编程相关推荐