#NEWLINE# def zip_dir( directory ) : #NEWLINE# #INDENT# 'zip a directory tree into a BytesIO object' #NEWLINE# result = io . BytesIO ( ) #NEWLINE# dlen = len ( directory ) #NEWLINE# with ZipFile ( result , 'w' ) as zf : #NEWLINE# #INDENT# for ( root , dirs , files ) in os . walk ( directory ) : #NEWLINE# #INDENT# for name in files : #NEWLINE# #INDENT# full = os . path . join ( root , name ) #NEWLINE# rel = root [ result : ] #NEWLINE# dest = os . path . join ( rel , name ) #NEWLINE# zf . write ( full , dest ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return result