Skip to content

Commit 1395379

Browse files
committed
Merge remote-tracking branch 'origin/main' into add-gpio-list
2 parents 9c6c5da + 17d8f01 commit 1395379

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/wokwi_client/client.py

Lines changed: 12 additions & 5 deletions
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, cast
78

@@ -15,7 +16,7 @@
1516
from .constants import DEFAULT_WS_URL
1617
from .control import set_control
1718
from .event_queue import EventQueue
18-
from .file_ops import download, download_file, upload, upload_file
19+
from .file_ops import download, upload, upload_file
1920
from .pins import gpio_list, pin_listen, pin_read
2021
from .protocol_types import EventMessage, ResponseMessage
2122
from .serial import monitor_lines, write_serial
@@ -92,17 +93,18 @@ async def upload_file(
9293
"""
9394
return await upload_file(self._transport, filename, local_path)
9495

95-
async def download(self, name: str) -> ResponseMessage:
96+
async def download(self, name: str) -> bytes:
9697
"""
9798
Download a file from the simulator.
9899
99100
Args:
100101
name: The name of the file to download.
101102
102103
Returns:
103-
The response message from the server.
104+
The downloaded file content as bytes.
104105
"""
105-
return await download(self._transport, name)
106+
result = await download(self._transport, name)
107+
return base64.b64decode(result["result"]["binary"])
106108

107109
async def download_file(self, name: str, local_path: Optional[Path] = None) -> None:
108110
"""
@@ -112,7 +114,12 @@ async def download_file(self, name: str, local_path: Optional[Path] = None) -> N
112114
name: The name of the file to download.
113115
local_path: The local path to save the downloaded file. If not provided, uses the name as the path.
114116
"""
115-
await download_file(self._transport, name, local_path)
117+
if local_path is None:
118+
local_path = Path(name)
119+
120+
result = await self.download(name)
121+
with open(local_path, "wb") as f:
122+
f.write(result)
116123

117124
async def start_simulation(
118125
self,

src/wokwi_client/file_ops.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,3 @@ async def upload(transport: Transport, name: str, content: bytes) -> ResponseMes
2626

2727
async def download(transport: Transport, name: str) -> ResponseMessage:
2828
return await transport.request("file:download", {"name": name})
29-
30-
31-
async def download_file(transport: Transport, name: str, local_path: Optional[Path] = None) -> None:
32-
if local_path is None:
33-
local_path = Path(name)
34-
35-
result = await download(transport, name)
36-
with open(local_path, "wb") as f:
37-
f.write(base64.b64decode(result["result"]["binary"]))

0 commit comments

Comments
 (0)