parameters: (root)
return_statement: return zip_file
docstring: Construct an in-memory zip file for a directory.
docstring_summary: Construct an in-memory zip file for a directory.
docstring_tokens: Construct an in - memory zip file for a directory .
function: def dir_to_zipfile(root):
      """Construct an in-memory zip file for a directory."""
      buffer = io.BytesIO()
      zip_file = zipfile.ZipFile(buffer, 'w')
      for root, dirs, files in os.walk(root):
          for path in dirs:
              fs_path = os.path.join(root, path)
              rel_path = os.path.relpath(fs_path, root)
              zip_file.writestr(rel_path + '/', '')
          for path in files:
              fs_path = os.path.join(root, path)
              rel_path = os.path.relpath(fs_path, root)
              zip_file.write(fs_path, rel_path)
      return zip_file
function_tokens: def dir_to_zipfile ( root ) : buffer = io . BytesIO ( ) zip_file = zipfile . ZipFile ( buffer , 'w' ) for root , dirs , files in os . walk ( root ) : for path in dirs : fs_path = os . path . join ( root , path ) rel_path = os . path . relpath ( fs_path , root ) zip_file . writestr ( rel_path + '/' , '' ) for path in files : fs_path = os . path . join ( root , path ) rel_path = os . path . relpath ( fs_path , root ) zip_file . write ( fs_path , rel_path ) return zip_file