Send data packets from the local file to the server
(filename: str, conn: Connection)
| 1490 | |
| 1491 | |
| 1492 | def _send_local_file(filename: str, conn: Connection): |
| 1493 | """Send data packets from the local file to the server""" |
| 1494 | packet_size = min(conn.max_allowed_packet, 16 * 1024) |
| 1495 | |
| 1496 | try: |
| 1497 | with open(filename, "rb") as file: |
| 1498 | # 16KB is efficient enough |
| 1499 | while True: |
| 1500 | chunk = file.read(packet_size) |
| 1501 | if not chunk: |
| 1502 | break |
| 1503 | conn.write_packet(chunk) |
| 1504 | except OSError as e: |
| 1505 | raise err.OperationalError( |
| 1506 | ER.FILE_NOT_FOUND, |
| 1507 | f"Can't open file '{filename}': {e}", |
| 1508 | ) |
no test coverage detected