From 6a4e4a7dd86db2b3b2c782b7575a2d8bfbb8b66c Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Tue, 6 Aug 2024 14:13:34 +0100 Subject: [PATCH] Handlers in place for start and end file transfer --- src/textual_serve/app_service.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/textual_serve/app_service.py b/src/textual_serve/app_service.py index 8271dcd..caccf22 100644 --- a/src/textual_serve/app_service.py +++ b/src/textual_serve/app_service.py @@ -232,12 +232,13 @@ class AppService: sys.stdout.write(error_text.decode("utf-8", "replace")) + readexactly = stdout.readexactly + int_from_bytes = int.from_bytes while True: - type_bytes = await stdout.readexactly(1) - size_bytes = await stdout.readexactly(4) - size = int.from_bytes(size_bytes, "big") - payload = await stdout.readexactly(size) - + type_bytes = await readexactly(1) + size_bytes = await readexactly(4) + size = int_from_bytes(size_bytes, "big") + payload = await readexactly(size) if type_bytes == DATA: await self.on_data(payload) elif type_bytes == META: @@ -291,6 +292,12 @@ class AppService: ] ) await self.remote_write_str(payload) + elif meta_type == "deliver_file_start": + # Let's start the file transfer process + pass + elif meta_type == "deliver_file_end": + # End the file transfer process + pass else: log.warning( f"Unknown meta type: {meta_type!r}. You may need to update `textual-serve`." @@ -302,3 +309,12 @@ class AppService: Args: payload: Encoded packed data. """ + + """ + { + "type": "deliver_file_start", + "key": key, + "path": str(path.resolve()), + "open_method": open_method, + } + """