handling tar, gz and bz2 with python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Thorley

    #1

    handling tar, gz and bz2 with python

    Is there a module for unpacking tar files in python? 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?

    thanks
    -Matthew
  • Fredrik Lundh

    #2
    Re: handling tar, gz and bz2 with python

    Matthew Thorley wrote:
    [color=blue]
    > Is there a module for unpacking tar files in python?[/color]
    [color=blue][color=green][color=darkred]
    >>> import tarfile
    >>> help(tarfile)[/color][/color][/color]
    ...
    | 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__.typ e
    | Open uncompressed tar archive name for reading or writing.
    ...
    [color=blue]
    > 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?[/color]

    see above.

    </F>

    Comment

    Working...