Send data packets from the local file to the server
(filename: str, conn: Connection)
| 1500 | |
| 1501 | |
| 1502 | def _send_local_file(filename: str, conn: Connection): |
| 1503 | """Send data packets from the local file to the server""" |
| 1504 | packet_size = min(conn.max_allowed_packet, 16 * 1024) |
| 1505 | |
| 1506 | try: |
| 1507 | with open(filename, "rb") as file: |
| 1508 | # 16KB is efficient enough |
| 1509 | while True: |
| 1510 | chunk = file.read(packet_size) |
| 1511 | if not chunk: |
| 1512 | break |
| 1513 | conn.write_packet(chunk) |
| 1514 | except OSError as e: |
| 1515 | raise err.OperationalError( |
| 1516 | ER.FILE_NOT_FOUND, |
| 1517 | f"Can't open file '{filename}': {e}", |
| 1518 | ) |
no test coverage detected