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

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

问题描述

一个人怎么可以检测该文件使用的COM pression的类型? (假设的.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?

推荐答案

您可以确定它是的可能的是这些格式中的一种通过观察前几个字节。然后,您应该测试,看看它是否真的的其中之一,使用相关工具的完整性检查该格式,或通过实际着手DECOM preSS。

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使得第一字节时间256加上第二个字​​节是31的倍数。

  • COM preSS(.Z)与0x1F的开始,0x9d

  • 的bzip2(操作.bz2)用的0x42开始,5AH即可,为0x68

  • zlib (.zz) format description, starts with (in bits) 0aaa1000 bbbccccc, where ccccc is chosen so that the first byte times 256 plus the second byte is a multiple of 31.
  • compress (.Z) starts with 0x1f, 0x9d
  • bzip2 (.bz2) starts with 0x42, 0x5a, 0x68

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

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