#!/usr/bin/env python # -*- coding: utf-8 -*- import os import _pylibtar TESTTAR = '/tmp/_pylibtar-test.tar' print 'opening %s for append' % TESTTAR tar = _pylibtar.pytar_open(TESTTAR, 'a') print 'tar:', tar print 'append:', _pylibtar.pytar_append_file(tar, __file__, os.path.basename(__file__)) print 'close:', _pylibtar.pytar_close(tar) print 'ITER' tar = _pylibtar.pytar_open(TESTTAR, 'r') print 'tar:', tar, 'ITER_RESET' print _pylibtar.pytar_iter_reset(tar) info = None while 1: try: print 'ITER_NEXT', os.lseek(_pylibtar.tar_fd(tar), 0, 1) info = _pylibtar.pytar_iter_next(tar) except StopIteration: break print 'INFO: %r' % info if not info: break if info: import sys print 'EXTRACTING %s' % info _pylibtar.pytar_extract(tar, info['offset'], sys.stdout.fileno())
def open(self): if self._tar is None: self._tar = _pylibtar.pytar_open(self.pathname, self.mode) return self._tar