Module tarfile
[hide private]
[frames] | no frames]

Module tarfile

Read from and write to tar format archives.


Version: $Revision: 51436 $

Date: $Date: 2006-08-22 04:43:51 +1000 (Tue, 22 Aug 2006) $

Author: Lars Gust\xe4bel (lars@gustaebel.de)

Classes [hide private]
TarError
Base exception.
ExtractError
General exception for extract errors.
ReadError
Exception for unreadble tar archives.
CompressionError
Exception for unavailable compression methods.
StreamError
Exception for unsupported operations on stream-like TarFiles.
_LowLevelFile
Low-level file object.
_Stream
Class that serves as an adapter between TarFile and a stream-like object.
_StreamProxy
Small proxy class that enables transparent compression detection for the Stream interface (mode 'r|*').
_BZ2Proxy
Small proxy class that enables external file object support for "r:bz2" and "w:bz2" modes.
ExFileObject
File-like object for reading an archive member.
TarInfo
Informational class which holds the details about an archive member given by a tar header block.
TarFile
The TarFile Class provides an interface to tar archives.
TarIter
Iterator Class.
_section
Base class for _data and _hole.
_data
Represent a data section in a sparse file.
_hole
Represent a hole section in a sparse file.
_ringbuffer
Ringbuffer class which increases performance over a regular list.
TarFileCompat
TarFile class compatible with standard module zipfile's ZipFile class.
Functions [hide private]
 
stn(s, length)
Convert a python string to a null-terminated string buffer.
 
nti(s)
Convert a number field to a python number.
 
itn(n, digits=8, posix=False)
Convert a python number to a number field.
 
calc_chksums(buf)
Calculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces.
 
copyfileobj(src, dst, length=None)
Copy length bytes from fileobj src to fileobj dst.
 
filemode(mode)
Convert a file's mode to a string of the form -rwxrwxrwx.
 
is_tarfile(name)
Return True if name points to a tar archive that we are able to handle, else return False.
Variables [hide private]
  version = '0.8.0'
  __cvsid__ = '$Id: tarfile.py 51436 2006-08-21 18:43:51Z neal.n...
  __credits__ = 'Gustavo Niemeyer, Niels Gust\xe4bel, Richard To...
  NUL = '\x00'
  BLOCKSIZE = 512
  RECORDSIZE = 10240
  MAGIC = 'ustar'
  VERSION = '00'
  LENGTH_NAME = 100
  LENGTH_LINK = 100
  LENGTH_PREFIX = 155
  MAXSIZE_MEMBER = 8589934591
  REGTYPE = '0'
  AREGTYPE = '\x00'
  LNKTYPE = '1'
  SYMTYPE = '2'
  CHRTYPE = '3'
  BLKTYPE = '4'
  DIRTYPE = '5'
  FIFOTYPE = '6'
  CONTTYPE = '7'
  GNUTYPE_LONGNAME = 'L'
  GNUTYPE_LONGLINK = 'K'
  GNUTYPE_SPARSE = 'S'
  SUPPORTED_TYPES = ('0', '\x00', '1', '2', '5', '6', '7', '3', ...
  REGULAR_TYPES = ('0', '\x00', '7', 'S')
  S_IFLNK = 40960
  S_IFREG = 32768
  S_IFBLK = 24576
  S_IFDIR = 16384
  S_IFCHR = 8192
  S_IFIFO = 4096
  TSUID = 2048
  TSGID = 1024
  TSVTX = 512
  TUREAD = 256
  TUWRITE = 128
  TUEXEC = 64
  TGREAD = 32
  TGWRITE = 16
  TGEXEC = 8
  TOREAD = 4
  TOWRITE = 2
  TOEXEC = 1
  filemode_table = (((40960, 'l'), (32768, '-'), (24576, 'b'), (...
  TAR_PLAIN = 0
  TAR_GZIPPED = 8

Imports: sys, os, shutil, stat, errno, time, struct, copy, pwd, grp, normpath, open


Function Details [hide private]

calc_chksums(buf)

 

Calculate the checksum for a member's header by summing up all characters except for the chksum field which is treated as if it was filled with spaces. According to the GNU tar sources, some tars (Sun and NeXT) calculate chksum with signed char, which will be different if there are chars in the buffer with the high bit set. So we calculate two checksums, unsigned and signed.

copyfileobj(src, dst, length=None)

 

Copy length bytes from fileobj src to fileobj dst. If length is None, copy the entire content.

filemode(mode)

 

Convert a file's mode to a string of the form -rwxrwxrwx. Used by TarFile.list()


Variables Details [hide private]

__cvsid__

Value:
'$Id: tarfile.py 51436 2006-08-21 18:43:51Z neal.norwitz $'

__credits__

Value:
'Gustavo Niemeyer, Niels Gust\xe4bel, Richard Townsend.'

SUPPORTED_TYPES

Value:
('0', '\x00', '1', '2', '5', '6', '7', '3', '4', 'L', 'K', 'S')

filemode_table

Value:
(((40960, 'l'),
  (32768, '-'),
  (24576, 'b'),
  (16384, 'd'),
  (8192, 'c'),
  (4096, 'p')),
 ((256, 'r')),
 ((128, 'w')),
...