如果重要的话,这是在 Mac 上。 zip 是版本 3.0,unzip 是版本 6.0(我期望操作系统附带的内容)。
如果我执行以下操作:
从通用“pptx”文件开始,将其解压缩到目录中,清理 XML,然后将其压缩
unzip V1.pptx -d dir
cd dir
find . -name "*.xml" -type f -exec xmllint --output '{}' --format '{}' \;
zip -0 ../V1Orig.pptx -r *
我现在有了一个新的 zip 文件 V1Orig.pptx
unzip V1Orig.pptx -d copy
cd copy
find . -name "*.xml" -type f -exec xmllint --output '{}' --format '{}' \;
zip -0 ../V1Copy.pptx -r *
如果我现在“比较”原始目录和复制目录,它们是相同的:
Common subdirectories: orig/_rels and copy/_rels
Common subdirectories: orig/docProps and copy/docProps
Common subdirectories: orig/ppt and copy/ppt
但是如果我比较 pptx 文件或对 pptx 进行 md5 校验和,我会得到不同的答案。
diff V1Orig.pptx V1Copy.pptx
Binary files V1Orig.pptx and V1Copy.pptx differ
ls -rtla orig
total 8
drwxr-xr-x 11 fultonm wheel 352 10 Jan 16:49 ppt
drwxr-xr-x 5 fultonm wheel 160 10 Jan 16:49 docProps
drwxr-xr-x 3 fultonm wheel 96 10 Jan 16:49 _rels
drwxr-xr-x 6 fultonm wheel 192 14 Jan 10:40 .
-rw-r--r-- 1 fultonm wheel 3212 14 Jan 10:42 [Content_Types].xml
drwxr-xr-x 8 fultonm wheel 256 14 Jan 10:57 ..
fultonm@mikes-MacBook-Pro-2 /tmp/handzip>ls -rtla copy
total 8
drwxr-xr-x 5 fultonm wheel 160 14 Jan 10:42 docProps
drwxr-xr-x 3 fultonm wheel 96 14 Jan 10:42 _rels
drwxr-xr-x 6 fultonm wheel 192 14 Jan 10:42 .
drwxr-xr-x 11 fultonm wheel 352 14 Jan 10:42 ppt
-rw-r--r-- 1 fultonm wheel 3212 14 Jan 10:42 [Content_Types].xml
drwxr-xr-x 8 fultonm wheel 256 14 Jan 10:57 ..
我认为问题在于正在记录时间戳。 这些当然会有所不同,因为 xmllint 过程改变了时代。
如果我这样做
unzip -l
我会看到放入zip文件的文件顺序是稳定的,因为它看起来是按名称而不是时间排序的,但日期和时间戳正在记录,当然,这些是不同的。
“修复”可能会确保任何 unzip/xmllint 步骤都不会更新时间戳,以便再次压缩时具有原始时间戳。
更好的答案表示赞赏!