connectors/ConnectorBase.py
changeset 2463 8742337a9fe3
child 2465 47d3aea2be30
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/connectors/ConnectorBase.py	Tue Dec 04 11:31:58 2018 +0100
@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# See COPYING file for copyrights details.
+
+import md5
+
+class ConnectorBase(object):
+
+    chuncksize = 16384
+    def BlobFromFile(self, filepath): 
+        s = md5.new()
+        blobID = s.digest()  # empty md5, to support empty blob
+        with open(filepath, "rb") as f:
+            while True:
+                chunk = f.read(self.chuncksize) 
+                if len(chunk) == 0: return blobID
+                blobID = self.AppendChunkToBlob(chunk, blobID)
+                s.update(chunk)
+                if blobID != s.digest(): return None
+