[Telepathy-commits] [telepathy-python/master] use the offset property when sending/receiving the file

Guillaume Desmottes guillaume.desmottes at collabora.co.uk
Thu Dec 4 06:00:19 PST 2008


---
 examples/file-transfer.py |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/examples/file-transfer.py b/examples/file-transfer.py
index 8d053c3..d32dbea 100644
--- a/examples/file-transfer.py
+++ b/examples/file-transfer.py
@@ -115,12 +115,17 @@ class FTReceiverClient(FTClient):
 
         if state == FT_STATE_OPEN:
             # receive file
+            offset = self.ft_channel[PROPERTIES_IFACE].Get(CHANNEL_TYPE_FILE_TRANSFER, 'InitialOffset')
             s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
             s.connect(self.sock_addr)
 
             path = self.create_output_path()
-            out = file(path, 'w')
-            read = 0
+            if offset == 0:
+                out = file(path, 'w')
+            else:
+                out = file(path, 'a')
+
+            read = offset
             while read < self.file_size:
                 data = s.recv(self.file_size - read)
                 read += len(data)
@@ -176,10 +181,11 @@ class FTSenderClient(FTClient):
 
         if state == FT_STATE_OPEN:
             # receive file
+            offset = self.ft_channel[PROPERTIES_IFACE].Get(CHANNEL_TYPE_FILE_TRANSFER, 'InitialOffset')
             s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
             s.connect(self.sock_addr)
 
-            s.send(file(self.file_to_offer).read())
+            s.send(file(self.file_to_offer).read()[offset:])
 
 def usage():
     print "Usage:\n" \
-- 
1.5.6.5




More information about the Telepathy-commits mailing list