Uncompressing Tar.z File With Python?
Solution 1:
If GZIP -- the application -- can handle it, you have two choices.
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.
Solution 2:
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?
Solution 3:
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).
Post a Comment for "Uncompressing Tar.z File With Python?"