Implementation function to write binary content to a file. Expects base64 encoded content from RFC transport.
(file_path: str, b64_content: str)
| 363 | |
| 364 | |
| 365 | def _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 | |
| 392 | def _delete_file_impl(file_path: str) -> bool: |