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

发布于 2024-11-27 18:48:51 字数 160 浏览 6 评论 0原文

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

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

干杯和感谢!

I have a few zip and rar files that I'm working with, and I'm trying to analyze the properties of how each file was compressed (compression level, compression algorithm (e.g. deflate, LZMA, BZip2), dictionary size, word size, etc.), and I haven't figured out a way to do this yet.

Is there any way to analyze the files to determine these properties, with software or otherwise?

Cheers and thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

子栖 2024-12-04 18:48:51

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

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

7zip properties

This is a fairly old question, but I wanted to throw in my two cents anyway since some of the methods above weren't as easy for me to use.

You can also determine this with 7-Zip. After opening the archive there is a column for method of compression:

7zip properties

森林散布 2024-12-04 18:48:51

对于 ZIP - 是的,zipinfo

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

For ZIP - yes, zipinfo

For RAR, the headers are easily found with either 7Zip or WinRAR, read the attached documentation

表情可笑 2024-12-04 18:48:51

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

7z l -slt archive.file

如果专门寻找压缩方法:

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

Via 7-Zip (or p7zip) command line:

7z l -slt archive.file

If looking specifically for the compression method:

7z l -slt archive.file | grep -e '^---' -e '^Path =' -e '^Method ='
热情消退 2024-12-04 18:48:51

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

python C:\Python27\Scripts\hachoir-wx

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

对于 RAR 文件,请查看 technote.txt 文件它位于 WinRAR 安装目录中。这提供了 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) 的哥哥亚历山大·L·罗沙尔 (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)

I suggest hachoir-wx to have a look at these files. How to install a Python package or you can try ActivePython with PyPM when using Windows. When you have the necessary hachoir packages installed, you can do something like this to run the GUI:

python C:\Python27\Scripts\hachoir-wx

It enables you to browse through the data fields of RAR and ZIP files. See this screenshot for an example.

For RAR files, have a look at the technote.txt file that is in the WinRAR installation directory. This gives detailed information of the RAR specification. You will probably be interested in these:

 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

Dictionary size can be found in the WinRAR GUI too.

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

And Wikipedia also knows this:

The RAR compression utility is proprietary, with a closed algorithm. RAR is owned by Alexander L. Roshal, the elder brother of Eugene Roshal. Version 3 of RAR is based on Lempel-Ziv (LZSS) and prediction by partial matching (PPM) compression, specifically the PPMd implementation of PPMII by Dmitry Shkarin.

For ZIP files I would start by having a look at the specifications and the ZIP Wikipedia page. These are probably interesting:

  general purpose bit flag: (2 bytes)
  compression method: (2 bytes)
夢归不見 2024-12-04 18:48:51

zipfile python 模块可用于获取有关 zip 文件的信息。
ZipInfo 类提供诸如 filenamecompress_typecompress_sizefile_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 模块可能有帮助

The zipfile python module can be used to get info about the zipfile.
The ZipInfo class provides information like filename, compress_type, compress_size, file_size etc...

Python snippet to get filename and the compress type of files in a zip archive

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}')

This would list all the filenames and their corresponding compression type(integer), which can be used to look up the compression method.
You can get a lot more info about the files using infolist().

The python module linked in the accepted answer is not available, zipfile module might help

煮茶煮酒煮时光 2024-12-04 18:48:51

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

For the ZIP files, there is a command zipinfo.

别闹i 2024-12-04 18:48:51

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

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

The type is easy, just look at the file headers (PK and Rar).

As for the rest, I doubt that information is available in the compressed content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文