def cat_extract(tar, member, targetpath):
 assert member.isreg()
 targetpath = targetpath.rstrip('/')
 targetpath = targetpath.replace('/', os.sep)
 upperdirs = os.path.dirname(targetpath)
 if (upperdirs and (not os.path.exists(upperdirs))):
  try:
   os.makedirs(upperdirs)
  except EnvironmentError as e:
   if (e.errno == errno.EEXIST):
    pass
   else:
    raise
 with files.DeleteOnError(targetpath) as dest:
  with pipeline.get_cat_pipeline(pipeline.PIPE, dest.f) as pl:
   fp = tar.extractfile(member)
   copyfileobj.copyfileobj(fp, pl.stdin)
 if (sys.version_info < (3, 5)):
  tar.chown(member, targetpath)
 else:
  tar.chown(member, targetpath, False)
 tar.chmod(member, targetpath)
 tar.utime(member, targetpath)

def cat_extract ( tar , member , targetpath ) : assert member . isreg ( ) targetpath = targetpath . rstrip ( '/' ) targetpath = targetpath . replace ( '/' , os . sep ) upperdirs = os . path . dirname ( targetpath ) if ( upperdirs and ( not os . path . exists ( upperdirs ) ) ) : try : os . makedirs ( upperdirs ) except EnvironmentError as e : if ( e . errno == errno . EEXIST ) : pass else : raise with files . DeleteOnError ( targetpath ) as dest : with pipeline . get_cat_pipeline ( pipeline . PIPE , dest . f ) as pl : fp = tar . extractfile ( member ) copyfileobj . copyfileobj ( fp , pl . stdin ) if ( sys . version_info < ( 3 , 5 ) ) : tar . chown ( member , targetpath ) else : tar . chown ( member , targetpath , False ) tar . chmod ( member , targetpath ) tar . utime ( member , targetpath )
extract a regular file member using cat for async-like i/o mostly adapted from tarfile .