Skip to content

Commit 4016c5f

Browse files
committed
feat: revert download and download_file methods to WokwiClient for file retrieval
1 parent 75909db commit 4016c5f

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/wokwi_client/client.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# SPDX-License-Identifier: MIT
44

5+
import base64
56
from pathlib import Path
67
from typing import Any, Optional, Union
78

@@ -14,7 +15,7 @@
1415
from .constants import DEFAULT_WS_URL
1516
from .control import set_control
1617
from .event_queue import EventQueue
17-
from .file_ops import upload, upload_file
18+
from .file_ops import download, upload, upload_file
1819
from .pins import pin_listen, pin_read
1920
from .protocol_types import EventMessage, ResponseMessage
2021
from .serial import monitor_lines, write_serial
@@ -91,6 +92,34 @@ async def upload_file(
9192
"""
9293
return await upload_file(self._transport, filename, local_path)
9394

95+
async def download(self, name: str) -> bytes:
96+
"""
97+
Download a file from the simulator.
98+
99+
Args:
100+
name: The name of the file to download.
101+
102+
Returns:
103+
The downloaded file content as bytes.
104+
"""
105+
result = await download(self._transport, name)
106+
return base64.b64decode(result["result"]["binary"])
107+
108+
async def download_file(self, name: str, local_path: Optional[Path] = None) -> None:
109+
"""
110+
Download a file from the simulator and save it to a local path.
111+
112+
Args:
113+
name: The name of the file to download.
114+
local_path: The local path to save the downloaded file. If not provided, uses the name as the path.
115+
"""
116+
if local_path is None:
117+
local_path = Path(name)
118+
119+
result = await self.download(name)
120+
with open(local_path, "wb") as f:
121+
f.write(result)
122+
94123
async def start_simulation(
95124
self,
96125
firmware: str,

0 commit comments

Comments
 (0)