def tar_stream(store, tree, mtime, format=''):
 buf = BytesIO()
 with closing(tarfile.open(None, ('w:%s' % format), buf)) as tar:
  for (entry_abspath, entry) in _walk_tree(store, tree):
   try:
    blob = store[entry.sha]
   except KeyError:
    continue
   data = ChunkedBytesIO(blob.chunked)
   info = tarfile.TarInfo()
   info.name = entry_abspath.decode('ascii')
   info.size = blob.raw_length()
   info.mode = entry.mode
   info.mtime = mtime
   tar.addfile(info, data)
   (yield buf.getvalue())
   buf.truncate(0)
   buf.seek(0)
 (yield buf.getvalue())

def tar_stream ( store , tree , mtime , format = '' ) : buf = BytesIO ( ) with closing ( tarfile . open ( None , ( 'w:%s' % format ) , buf ) ) as tar : for ( entry_abspath , entry ) in _walk_tree ( store , tree ) : try : blob = store [ entry . sha ] except KeyError : continue data = ChunkedBytesIO ( blob . chunked ) info = tarfile . TarInfo ( ) info . name = entry_abspath . decode ( 'ascii' ) info . size = blob . raw_length ( ) info . mode = entry . mode info . mtime = mtime tar . addfile ( info , data ) ( yield buf . getvalue ( ) ) buf . truncate ( 0 ) buf . seek ( 0 ) ( yield buf . getvalue ( ) )
generate a tar stream for the contents of a git tree .