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