20

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

有没有办法通过软件或其他方式分析文件以确定这些属性?

干杯和感谢!

4

7 回答 7

14

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

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

7zip 属性

于 2012-07-02T15:06:25.383 回答
8

对于 ZIP - 是的,zipinfo

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

于 2011-08-25T15:15:57.247 回答
4

我建议hach​​oir-wx看看这些文件。如何安装 Python 包,或者您可以在使用 Windows 时尝试ActivePython和 PyPM。当您安装了必要的 hach​​oir 包后,您可以执行以下操作来运行 GUI:

python C:\Python27\Scripts\hachoir-wx

它使您能够浏览 RAR 和 ZIP 文件的数据字段。有关示例,请参阅此屏幕截图。

对于 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

维基百科也知道这一点:

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

对于 ZIP 文件,我会先查看规范ZIP 维基百科页面。这些可能很有趣:

  general purpose bit flag: (2 bytes)
  compression method: (2 bytes)
于 2011-08-02T15:32:34.217 回答
3

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

7z l -slt archive.file

如果专门寻找压缩方法:

7z l -slt archive.file | grep -e '^---' -e '^Path =' -e '^Method ='
于 2018-02-22T07:08:31.500 回答
1

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

于 2011-08-02T15:43:42.003 回答
0

类型很简单,只需查看文件头(PKRar)。

至于其余的,我怀疑压缩内容中是否提供信息。

于 2011-08-01T09:43:56.177 回答
0

zipfile python 模块可用于获取有关 zipfile 的信息。该类ZipInfo提供诸如filename, compress_type, compress_size,file_size等信息...

用于获取 zip 存档中文件名和文件压缩类型的 Python 片段

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()
获得有关文件的更多信息。

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

于 2020-11-27T10:28:18.353 回答