如何确定ZIP / RAR文件的压缩方法

时间:2011-08-01 09:27:50

标签: algorithm compression zip rar

我有一些我正在使用的zip和rar文件,我正在尝试分析每个文件的压缩属性(压缩级别,压缩算法(例如deflate,LZMA,BZip2),字典大小) ,字大小等),我还没有找到办法做到这一点。

有没有办法用软件或其他方法分析文件来确定这些属性?

干杯谢谢!

7 个答案:

答案 0 :(得分:10)

这是一个相当古老的问题,但我还是想投入两分钱,因为上面的一些方法对我来说并不容易。

您也可以使用7-Zip确定这一点。打开存档后,有一列压缩方法:

7zip properties

答案 1 :(得分:6)

对于ZIP - 是的,zipinfo

对于RAR,可以使用7Zip或WinRAR轻松找到标题,请阅读附带的文档

答案 2 :(得分:4)

我建议hachoir-wx查看这些文件。 How to install a Python package或者您在使用Windows时可以使用PyPM尝试ActivePython。当您安装了必要的hachoir软件包时,您可以执行以下操作来运行GUI:

  

python C:\ Python27 \ Scripts \ hach​​oir-wx

它使您可以浏览RAR和ZIP文件的数据字段。有关示例,请参阅此screenshot

对于RAR文件,请查看WinRAR安装目录中的technote.txt文件。这提供了RAR规范的详细信息。你可能会对这些感兴趣:

 HEAD_FLAGS      Bit flags: 2 bytes
                 0x10 - information from previous files is used (solid flag)
                 bits 7 6 5 (for RAR 2.0 and later)
                      0 0 0    - dictionary size   64 KB
                      0 0 1    - dictionary size  128 KB
                      0 1 0    - dictionary size  256 KB
                      0 1 1    - dictionary size  512 KB
                      1 0 0    - dictionary size 1024 KB
                      1 0 1    - dictionary size 2048 KB
                      1 1 0    - dictionary size 4096 KB
                      1 1 1    - file is directory

字典大小也可以在WinRAR GUI中找到。

 METHOD          Packing method 1 byte
                 0x30 - storing
                 0x31 - fastest compression
                 0x32 - fast compression
                 0x33 - normal compression
                 0x34 - good compression
                 0x35 - best compression

Wikipedia也知道这一点:

  

RAR压缩实用程序是专有的,具有封闭算法。 RAR由Eugene Roshal的哥哥Alexander L. Roshal拥有。 RAR第3版基于Lempel-Ziv(LZSS)和部分匹配(PPM)压缩预测,特别是Dmitry Shkarin对PPMII的PPMd实施。

对于ZIP文件,我首先要查看specificationsZIP Wikipedia page。这些可能很有趣:

  general purpose bit flag: (2 bytes)
  compression method: (2 bytes)

答案 3 :(得分:2)

通过7-Zip(或p7zip)命令行:

7z l -slt archive.file

如果专门研究压缩方法:

7z l -slt archive.file | grep -e '^---' -e '^Path =' -e '^Method ='

答案 4 :(得分:1)

对于ZIP文件,有一个命令zipinfo。

答案 5 :(得分:0)

类型很简单,只需查看文件标题(PKRar)即可。

至于其他方面,我怀疑压缩内容中是否有可用的信息。

答案 6 :(得分:0)

zipfile python模块可用于获取有关zipfile的信息。 ZipInfo类提供诸如filenamecompress_typecompress_sizefile_size等信息。

Python代码段可获取zip归档文件中的文件名和压缩类型

import zipfile

with zipfile.ZipFile(path_to_zipfile, 'r') as zip:
    for info in zip.infolist():
        print(f'filename: {info.filename}')
        print(f'compress type: {info.compress_type}')

这将列出所有文件名及其对应的压缩类型(整数),可用于查找压缩方法。
您可以使用infolist()了解有关文件的更多info

在接受的答案中链接的python模块不可用,zipfile模块可能有帮助