handling tar, gz and bz2 with python

Fredrik Lundh fredrik at pythonware.com
Fri Apr 22 17:04:46 EDT 2005


Matthew Thorley wrote:

> Is there a module for unpacking tar files in python?

>>> import tarfile
>>> help(tarfile)
    ...
     |  open(cls, name=None, mode='r', fileobj=None, bufsize=10240) from __built
in__.type
     |      Open a tar archive for reading, writing or appending. Return
     |      an appropriate TarFile class.
     |
     |      mode:
     |      'r'          open for reading with transparent compression
     |      'r:'         open for reading exclusively uncompressed
     |      'r:gz'       open for reading with gzip compression
     |      'r:bz2'      open for reading with bzip2 compression
     |      'a' or 'a:'  open for appending
     |      'w' or 'w:'  open for writing without compression
     |      'w:gz'       open for writing with gzip compression
     |      'w:bz2'      open for writing with bzip2 compression
     |      'r|'         open an uncompressed stream of tar blocks for reading
     |      'r|gz'       open a gzip compressed stream of tar blocks
     |      'r|bz2'      open a bzip2 compressed stream of tar blocks
     |      'w|'         open an uncompressed stream for writing
     |      'w|gz'       open a gzip compressed stream for writing
     |      'w|bz2'      open a bzip2 compressed stream for writing
     |
     |  taropen(cls, name, mode='r', fileobj=None) from __builtin__.type
     |      Open uncompressed tar archive name for reading or writing.
    ...

> how about bzip2 and gzips? I know I can use the gzip module for gzips
> but is there anything that can detect what format a file is in and decopress
> and unpack it using the other methods?

see above.

</F>




More information about the Python-list mailing list