connectors/ConnectorBase.py
changeset 2487 6a4f9a061994
parent 2465 47d3aea2be30
child 2492 7dd551ac2fa0
equal deleted inserted replaced
2486:44c2a4e2b84d 2487:6a4f9a061994
     7 
     7 
     8 class ConnectorBase(object):
     8 class ConnectorBase(object):
     9 
     9 
    10     #chuncksize = 16384
    10     #chuncksize = 16384
    11     chuncksize = 1024*1024
    11     chuncksize = 1024*1024
    12     def BlobFromFile(self, filepath): 
    12     def BlobFromFile(self, filepath, seed):
    13         s = md5.new()
    13         s = md5.new()
    14         blobID = s.digest()  # empty md5, to support empty blob
    14         s.update(seed)
       
    15         blobID = self.SeedBlob(seed)
    15         with open(filepath, "rb") as f:
    16         with open(filepath, "rb") as f:
    16             while True:
    17             while blobID == s.digest():
    17                 chunk = f.read(self.chuncksize) 
    18                 chunk = f.read(self.chuncksize) 
    18                 if len(chunk) == 0: return blobID
    19                 if len(chunk) == 0: return blobID
    19                 blobID = self.AppendChunkToBlob(chunk, blobID)
    20                 blobID = self.AppendChunkToBlob(chunk, blobID)
    20                 s.update(chunk)
    21                 s.update(chunk)
    21                 if blobID != s.digest(): return None
       
    22 
    22