connectors/ConnectorBase.py
changeset 2492 7dd551ac2fa0
parent 2487 6a4f9a061994
child 2540 fca79ca84272
equal deleted inserted replaced
2491:362039519454 2492:7dd551ac2fa0
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 # See COPYING file for copyrights details.
     4 # See COPYING file for copyrights details.
     5 
     5 
       
     6 from __future__ import absolute_import
     6 import md5
     7 import md5
       
     8 
     7 
     9 
     8 class ConnectorBase(object):
    10 class ConnectorBase(object):
     9 
    11 
    10     #chuncksize = 16384
       
    11     chuncksize = 1024*1024
    12     chuncksize = 1024*1024
       
    13 
    12     def BlobFromFile(self, filepath, seed):
    14     def BlobFromFile(self, filepath, seed):
    13         s = md5.new()
    15         s = md5.new()
    14         s.update(seed)
    16         s.update(seed)
    15         blobID = self.SeedBlob(seed)
    17         blobID = self.SeedBlob(seed)
    16         with open(filepath, "rb") as f:
    18         with open(filepath, "rb") as f:
    17             while blobID == s.digest():
    19             while blobID == s.digest():
    18                 chunk = f.read(self.chuncksize) 
    20                 chunk = f.read(self.chuncksize)
    19                 if len(chunk) == 0: return blobID
    21                 if len(chunk) == 0:
       
    22                     return blobID
    20                 blobID = self.AppendChunkToBlob(chunk, blobID)
    23                 blobID = self.AppendChunkToBlob(chunk, blobID)
    21                 s.update(chunk)
    24                 s.update(chunk)
    22