2
0
Эх сурвалжийг харах

Provide more complete file-like API to pack write commands, since they need tell().

Jelmer Vernooij 16 жил өмнө
parent
commit
1055c2dc3d
1 өөрчлөгдсөн 19 нэмэгдсэн , 0 устгасан
  1. 19 0
      dulwich/protocol.py

+ 19 - 0
dulwich/protocol.py

@@ -97,6 +97,25 @@ class Protocol(object):
         except socket.error, e:
             raise GitProtocolError(e)
 
+    def write_file(self):
+        class ProtocolFile(object):
+
+            def __init__(self, proto):
+                self._proto = proto
+                self._offset = 0
+
+            def write(self, data):
+                self._proto.write(data)
+                self._offset += len(data)
+
+            def tell(self):
+                return self._offset
+
+            def close(self):
+                pass
+
+        return ProtocolFile(self)
+
     def write_sideband(self, channel, blob):
         """
         Write data to the sideband (a git multiplexing method)