New in version 2.3.
The tarfile module makes it possible to read and create tar archives. Some facts and figures:
|[name[, mode [, fileobj[, bufsize]]]])|
mode has to be a string of the form
it defaults to
'r'. Here is a full list of mode combinations:
||Open for reading with transparent compression (recommended).|
||Open for reading exclusively without compression.|
||Open for reading with gzip compression.|
||Open for reading with bzip2 compression.|
||Open for appending with no compression.|
||Open for uncompressed writing.|
||Open for gzip compressed writing.|
||Open for bzip2 compressed writing.|
'a:bz2' is not possible.
If mode is not suitable to open a certain (compressed) file for
reading, ReadError is raised. Use mode
avoid this. If a compression method is not supported,
CompressionError is raised.
If fileobj is specified, it is used as an alternative to a file object opened for name.
For special purposes, there is a second format for mode:
open will return a TarFile
object that processes its data as a stream of blocks. No random
seeking will be done on the file. If given, fileobj may be any
object that has a
bufsize specifies the blocksize and defaults to
20 * 512
bytes. Use this variant in combination with e.g.
sys.stdin, a socket
file object or a tape device.
However, such a TarFile object is limited in that it does not allow
to be accessed randomly, see Examples (section
The currently possible modes:
||Open a stream of uncompressed tar blocks for reading.|
||Open a gzip compressed stream for reading.|
||Open a bzip2 compressed stream for reading.|
||Open an uncompressed stream for writing.|
||Open an gzip compressed stream for writing.|
||Open an bzip2 compressed stream for writing.|
Trueif name is a tar archive file, that the tarfile module can read.
|filename[, mode[, compression]])|
Class for limited access to tar archives with a
interface. Please consult the documentation of
zipfile for more
compression must be one of the following constants:
gzipcompressed tar archive.