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