

















我们可以用 zipinfo 命令直观地看到有无 Extra Field 的区别。先创建一个测试目录:
mkdir -p /tmp/zip-test/demo echo "hello world" > /tmp/zip-test/demo/hello.txt chmod 755 /tmp/zip-test/demo/hello.txt
分别用默认方式和 -X 选项打包:
cd /tmp/zip-test
zip -r with-extra.zip demo/
zip -rX without-extra.zip demo/
adding: demo/ (stored 0%) adding: demo/hello.txt (stored 0%) adding: demo/ (stored 0%) adding: demo/hello.txt (stored 0%)
用 zipinfo 查看包含 Extra Field 的版本:
zipinfo /tmp/zip-test/with-extra.zip
Archive: /tmp/zip-test/with-extra.zip Zip file size: 328 bytes, number of entries: 2 drwxr-xr-x 3.0 unx 0 bx stor 26-Apr-15 23:01 demo/ -rwxr-xr-x 3.0 unx 12 tx stor 26-Apr-15 23:01 demo/hello.txt 2 files, 12 bytes uncompressed, 12 bytes compressed: 0.0%
注意输出中的 unx 和 bx / tx : unx 表示 Unix 格式的条目, bx / tx 中的 x 表示文件保留了可执行权限。
再看不含 Extra Field 的版本:
zipinfo /tmp/zip-test/without-extra.zip
Archive: /tmp/zip-test/without-extra.zip Zip file size: 224 bytes, number of entries: 2 drwxr-xr-x 3.0 unx 0 b- stor 26-Apr-15 23:01 demo/ -rwxr-xr-x 3.0 unx 12 t- stor 26-Apr-15 23:01 demo/hello.txt 2 files, 12 bytes uncompressed, 12 bytes compressed: 0.0%
用 zipinfo -v 可以看到更详细的差异:
zipinfo -v /tmp/zip-test/with-extra.zip | grep -E "(length of extra field|central-directory extra field|subfield with ID)"
length of extra field: 24 bytes The central-directory extra field contains: - A subfield with ID 0x5455 (universal time) and 5 data bytes. - A subfield with ID 0x7875 (Unix UID/GID (any size)) and 11 data bytes: length of extra field: 24 bytes The central-directory extra field contains: - A subfield with ID 0x5455 (universal time) and 5 data bytes. - A subfield with ID 0x7875 (Unix UID/GID (any size)) and 11 data bytes:
对比不含 Extra Field 的版本:
zipinfo -v /tmp/zip-test/without-extra.zip | grep "extra field"
length of extra field: 0 bytes length of extra field: 0 bytes
文件大小的差异也很明显:328 bytes vs 224 bytes,差了 104 bytes,正好是两个条目各 24 bytes 的 Extra Field(包含 Universal Time 和 Unix UID/GID)加上头部开销。
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。