connectors/ConnectorBase.py
changeset 2463 8742337a9fe3
child 2465 47d3aea2be30
equal deleted inserted replaced
2462:ed6b0e905fcb 2463:8742337a9fe3
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # See COPYING file for copyrights details.
       
     5 
       
     6 import md5
       
     7 
       
     8 class ConnectorBase(object):
       
     9 
       
    10     chuncksize = 16384
       
    11     def BlobFromFile(self, filepath): 
       
    12         s = md5.new()
       
    13         blobID = s.digest()  # empty md5, to support empty blob
       
    14         with open(filepath, "rb") as f:
       
    15             while True:
       
    16                 chunk = f.read(self.chuncksize) 
       
    17                 if len(chunk) == 0: return blobID
       
    18                 blobID = self.AppendChunkToBlob(chunk, blobID)
       
    19                 s.update(chunk)
       
    20                 if blobID != s.digest(): return None
       
    21