如何检测文件上使用的压缩类型?(如果没有指定文件扩展名) [英] How to detect type of compression used on the file? (if no file extension is specified)

查看:38
本文介绍了如何检测文件上使用的压缩类型?(如果没有指定文件扩展名)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检测文件上使用的压缩类型?(假设未指定 .zip、.gz、.xz 或任何其他扩展名).

How can one detect the type of compression used on the file? (assuming that .zip, .gz, .xz or any other extension is not specified).

这些信息是否存储在该文件的标题中?

Is this information stored somewhere in the header of that file?

推荐答案

您可以通过查看前几个字节来确定可能是其中一种格式.然后,您应该测试它是否真的 其中之一,使用来自该格式的相关实用程序的完整性检查,或者通过实际进行解压缩.

You can determine that it is likely to be one of those formats by looking at the first few bytes. You should then test to see if it really is one of those, using an integrity check from the associated utility for that format, or by actually proceeding to decompress.

您可以在描述中找到标题格式:

You can find the header formats in the descriptions:

  • Zip (.zip) format description, starts with 0x50, 0x4b, 0x03, 0x04 (unless empty — then the last two are 0x05, 0x06 or 0x06, 0x06)
  • Gzip (.gz) format description, starts with 0x1f, 0x8b, 0x08
  • xz (.xz) format description, starts with 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00

其他:

  • zlib (.zz) 格式说明,以两个字节开头(以位为单位) 0aaa1000 bbbccccc,其中选择 ccccc 以使第一个字节被视为 int16 乘以 256 加上第二个字​​节被视为 int16 是 31 的倍数.例如:01111000(bits) = 120(int16), 10011100(bits) =156(int16), 120 * 256 + 156 = 30876 是 31 的倍数
  • 压缩 (.Z) 以 0x1f、0x9d 开头
  • bzip2 (.bz2) 以 0x42、0x5a、0x68 开头
  • Zstandard (.zstd) 格式说明,帧以 4 字节魔法开头little-endian 格式 0xFD2FB528 的数字,可跳过的帧以 0x184D2A5? 开头(问号是从 0 到 F 的任何值)和字典以 0xEC30A437 开头.
  • magic 数据库中的更多格式来自file 命令
  • zlib (.zz) format description, starts with two bytes (in bits) 0aaa1000 bbbccccc, where ccccc is chosen so that the first byte viewed as a int16 times 256 plus the second byte viewed as a int16 is a multiple of 31. e.g: 01111000(bits) = 120(int16), 10011100(bits) = 156(int16), 120 * 256 + 156 = 30876 which is a multiple of 31
  • compress (.Z) starts with 0x1f, 0x9d
  • bzip2 (.bz2) starts with 0x42, 0x5a, 0x68
  • Zstandard (.zstd) format description, frame starts with a 4 byte magic number using little-endian format 0xFD2FB528, a skipable frame starts with 0x184D2A5? (question mark is any value from 0 to F), and dictionary starts with 0xEC30A437.
  • A few more formats in the magic database from the file command

这篇关于如何检测文件上使用的压缩类型?(如果没有指定文件扩展名)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆