uncompressing tar.Z file with python?

三世轮回 提交于 2019-12-01 13:11:08

If GZIP -- the application -- can handle it, you have two choices.

  1. Try the Python gzip library. It may work.

  2. Use subprocess Popen to run gzip for you.

It may be an InstallShield .Z file. You may want to use InstallShield to unpack it and extract the .TAR file. Again, you may be able to use subprocess Popen to process the file.

It may also be a "LZW compressed file". Look at this library, it may help.

http://www.chilkatsoft.com/compression-python.asp

Since you target a specific platform (Windows), the simplest solution may be to run gzip in a system call: http://www.gzip.org/#exe

Are there other requirements in your project that the decompression needs to be done in Python?

A plain Python module that uncompresses is inexistant, AFAIK, but it's feasible to build one, given some knowledge:

  • the .Z format header specification
  • the .Z compression format

Almost all necessary information can be found the unarchiver CompressAlgorithm. Additional info from wikipedia for adaptive LZW and perhaps the compress man page.

Basically, you read the first three bytes (first two are magic bytes) to modify your algorithm, and then start reading and decompressing.

There's a lot of bit fiddling (.Z files begin having 9-bit tokens, up to 16-bit ones and then resetting the symbol table to the initial 256+2 values), which probably you'll deal with doing binary operations (&, <<= etc).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!