TarFile
methods that are compatible to zipfile:
'r'
for reading an existing file (default), 'a'
for
appending/creating a file or 'w'
to create a new file replacing an existing one. Appending to a gzipped
TAR file is not allowed, and raises an exception.
compression must be one of the constants TAR_PLAIN
for creating an uncompressed
or TAR_GZIPPED
for a gzipped TAR file. It defaults to TAR_PLAIN
.TarFile
. It is recommended that you call close() before exiting your program.TarInfo
object with information about archive entry name. See
TarInfo
Objects.TarInfo
Objects one for each entry in the TarFile
. The list
has the same order as the entries in the TarFile
.sys.stdout
.testzip
()TarFile
. Return the name of the first bad file, else None
.TarFile
giving it the name arcname in the TarFile
(optional).
If filename is the name of a directory, all files in this directory and its subdirectories
are written to the TarFile
. If recursive is false only the directory is written
to the TarFile
, without adding any underlying file. recursive is true by default.
compress_type exists for compatibility to zipfile but has no effect.
The TarFile
must be opened with mode 'a'
or 'w'
.
TarFile
. tarinfo is a TarInfo
instance that provides additional
information about bytes. At least filename and date_time must be given.
The TarFile
must be opened with mode 'a'
or 'w'
.TarFile
provides some additional methods, which can not be found in zipfile:
TarFile
entry determined either by its name or its TarInfo
Object
to current working directory or to path (if given).
This method is recommended over read(), because it additionally extracts detailed file information
like file type, file permissions, userid etc. See TarInfo
for more details.
TarFile
as a TarInfo
instance. Return None
if there is no more
entry available. This method is intended to be used in a while
statement.
TarFile
Class has to go through the entire archive at startup to gain information
about the entries. This can take some time when the archive contains a large number of files.
If you use the next() method, you can go through the archive entry by entry, and reading
in the contents at startup is avoided.
TarFile
furthermore makes it possible to go through its entries by Iteration. For example,
you can write some code like this:
for tarinfo in TarFile(...): [...]This feature is first introduced in Python version 2.2. Users of Python less than 2.2 can use the next() method in combination with
while
described above.TarFile
provides the following class attributes:
0
(no messages, default) and 3
(all messages). The debugging output
is written to sys.stdout
.