MCPcopy Index your code
hub / github.com/python/cpython / _FileInFile

Class _FileInFile

Lib/tarfile.py:614–719  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

612# Extraction file object
613#------------------------
614class _FileInFile(object):
615 """A thin wrapper around an existing file object that
616 provides a part of its data as an individual file
617 object.
618 """
619
620 def __init__(self, fileobj, offset, size, name, blockinfo=None):
621 self.fileobj = fileobj
622 self.offset = offset
623 self.size = size
624 self.position = 0
625 self.name = name
626 self.closed = False
627
628 if blockinfo is None:
629 blockinfo = [(0, size)]
630
631 # Construct a map with data and zero blocks.
632 self.map_index = 0
633 self.map = []
634 lastpos = 0
635 realpos = self.offset
636 for offset, size in blockinfo:
637 if offset > lastpos:
638 self.map.append((False, lastpos, offset, None))
639 self.map.append((True, offset, offset + size, realpos))
640 realpos += size
641 lastpos = offset + size
642 if lastpos < self.size:
643 self.map.append((False, lastpos, self.size, None))
644
645 def flush(self):
646 pass
647
648 @property
649 def mode(self):
650 return 'rb'
651
652 def readable(self):
653 return True
654
655 def writable(self):
656 return False
657
658 def seekable(self):
659 return self.fileobj.seekable()
660
661 def tell(self):
662 """Return the current file position.
663 """
664 return self.position
665
666 def seek(self, position, whence=io.SEEK_SET):
667 """Seek to a position in the file.
668 """
669 if whence == io.SEEK_SET:
670 self.position = min(max(position, 0), self.size)
671 elif whence == io.SEEK_CUR:

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…