aesgcm_decrypt_generator. Cryptography helper for encrypting/decrypting application data. This docstring was expanded to make future maintenance easier. Args: src_path: Parameter. Returns: Varies.
(src_path: str)
| 568 | return None |
| 569 | |
| 570 | def _save_plain_upload(file_storage, tmp_path: str) -> int: |
| 571 | """Save uploaded file to disk quickly (plain) and return size. |
| 572 | |
| 573 | Speed notes: |
| 574 | - Prefer Werkzeug's built-in `save()` which streams efficiently to disk. |
| 575 | - Fallback to a large-buffer copy for environments where `save()` misbehaves. |
| 576 | """ |
| 577 | os.makedirs(os.path.dirname(tmp_path), exist_ok=True) |
| 578 | |
| 579 | # Fast path: Werkzeug's streaming save (usually the quickest). |
| 580 | try: |
| 581 | file_storage.save(tmp_path) |
| 582 | return int(os.path.getsize(tmp_path)) |
| 583 | except Exception: |
| 584 | pass |
| 585 | |
| 586 | # Fallback: manual copy with a large buffer (minimize Python overhead). |
| 587 | size = 0 |
| 588 | try: |
| 589 | try: |
| 590 | file_storage.stream.seek(0) |
| 591 | except Exception: |
| 592 | pass |
| 593 | with open(tmp_path, "wb") as out: |
| 594 | shutil.copyfileobj(file_storage.stream, out, length=8 * 1024 * 1024) # 8 MiB buffer |
| 595 | size = int(os.path.getsize(tmp_path)) |
| 596 | except Exception: |
| 597 | # Last resort: try save again (some backends reset stream after failure) |
| 598 | file_storage.save(tmp_path) |
| 599 | size = int(os.path.getsize(tmp_path)) |
| 600 | return int(size) |
| 601 | |
| 602 | def _bg_encrypt_file(tmp_plain: str, out_enc: str, finalize_fn): |
| 603 | """Encrypt tmp_plain -> out_enc in a background thread, then call finalize_fn(success:bool, err:str|None).""" |
| 604 | def worker(): |
| 605 | """worker. |
no outgoing calls
no test coverage detected