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