MCPcopy
hub / github.com/agent0ai/agent-zero / _write_file_binary_impl

Function _write_file_binary_impl

helpers/rfc_files.py:365–389  ·  view source on GitHub ↗

Implementation function to write binary content to a file. Expects base64 encoded content from RFC transport.

(file_path: str, b64_content: str)

Source from the content-addressed store, hash-verified

363
364
365def _write_file_binary_impl(file_path: str, b64_content: str) -> bool:
366 """
367 Implementation function to write binary content to a file.
368 Expects base64 encoded content from RFC transport.
369 """
370 try:
371 # Ensure b64_content is properly UTF-8 encoded before base64 decoding
372 if isinstance(b64_content, str):
373 b64_content_bytes = b64_content.encode('utf-8')
374 else:
375 b64_content_bytes = b64_content
376
377 # Decode base64 content
378 content = base64.b64decode(b64_content_bytes)
379
380 # Create directory if it doesn't exist
381 os.makedirs(os.path.dirname(file_path), exist_ok=True)
382
383 # Write file
384 with open(file_path, 'wb') as file:
385 file.write(content)
386
387 return True
388 except Exception as e:
389 raise Exception(f"Failed to write file {file_path}: {str(e)}")
390
391
392def _delete_file_impl(file_path: str) -> bool:

Callers

nothing calls this directly

Calls 3

openFunction · 0.50
encodeMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected