Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
tarfile._FileInFile Class Reference
Inheritance diagram for tarfile._FileInFile:
Inheritance graph
[legend]
Collaboration diagram for tarfile._FileInFile:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def seekable
def tell
def seek
def read

Public Attributes

 fileobj
 offset
 size
 position
 map_index
 map
_PyObject_HEAD_EXTRA Py_ssize_t ob_refcnt
struct _typeobjectob_type

Detailed Description

A thin wrapper around an existing file object that
   provides a part of its data as an individual file
   object.

Definition at line 698 of file tarfile.py.


Constructor & Destructor Documentation

def tarfile._FileInFile.__init__ (   self,
  fileobj,
  offset,
  size,
  blockinfo = None 
)

Definition at line 704 of file tarfile.py.

00704 
00705     def __init__(self, fileobj, offset, size, blockinfo=None):
00706         self.fileobj = fileobj
00707         self.offset = offset
00708         self.size = size
00709         self.position = 0
00710 
00711         if blockinfo is None:
00712             blockinfo = [(0, size)]
00713 
00714         # Construct a map with data and zero blocks.
00715         self.map_index = 0
00716         self.map = []
00717         lastpos = 0
00718         realpos = self.offset
00719         for offset, size in blockinfo:
00720             if offset > lastpos:
00721                 self.map.append((False, lastpos, offset, None))
00722             self.map.append((True, offset, offset + size, realpos))
00723             realpos += size
00724             lastpos = offset + size
00725         if lastpos < self.size:
00726             self.map.append((False, lastpos, self.size, None))

Here is the caller graph for this function:


Member Function Documentation

def tarfile._FileInFile.read (   self,
  size = None 
)
Read data from the file.

Definition at line 743 of file tarfile.py.

00743 
00744     def read(self, size=None):
00745         """Read data from the file.
00746         """
00747         if size is None:
00748             size = self.size - self.position
00749         else:
00750             size = min(size, self.size - self.position)
00751 
00752         buf = b""
00753         while size > 0:
00754             while True:
00755                 data, start, stop, offset = self.map[self.map_index]
00756                 if start <= self.position < stop:
00757                     break
00758                 else:
00759                     self.map_index += 1
00760                     if self.map_index == len(self.map):
00761                         self.map_index = 0
00762             length = min(size, stop - self.position)
00763             if data:
00764                 self.fileobj.seek(offset + (self.position - start))
00765                 buf += self.fileobj.read(length)
00766             else:
00767                 buf += NUL * length
00768             size -= length
00769             self.position += length
00770         return buf
00771 #class _FileInFile
00772 

Here is the caller graph for this function:

def tarfile._FileInFile.seek (   self,
  position 
)
Seek to a position in the file.

Definition at line 738 of file tarfile.py.

00738 
00739     def seek(self, position):
00740         """Seek to a position in the file.
00741         """
00742         self.position = position

Here is the caller graph for this function:

Definition at line 727 of file tarfile.py.

00727 
00728     def seekable(self):
00729         if not hasattr(self.fileobj, "seekable"):
00730             # XXX gzip.GzipFile and bz2.BZ2File
00731             return True
00732         return self.fileobj.seekable()

def tarfile._FileInFile.tell (   self)
Return the current file position.

Definition at line 733 of file tarfile.py.

00733 
00734     def tell(self):
00735         """Return the current file position.
00736         """
00737         return self.position


Member Data Documentation

Definition at line 705 of file tarfile.py.

Definition at line 715 of file tarfile.py.

Definition at line 714 of file tarfile.py.

Definition at line 107 of file object.h.

struct _typeobject* _object::ob_type [inherited]

Definition at line 108 of file object.h.

Definition at line 706 of file tarfile.py.

Definition at line 708 of file tarfile.py.

Definition at line 707 of file tarfile.py.


The documentation for this class was generated from the following file: