connectors/ConnectorBase.py
author GP Orcullo <kinsamanka@gmail.com>
Fri, 28 Oct 2022 14:07:13 +0800
branchpython3
changeset 3752 9f6f46dbe3ae
parent 3750 f62625418bff
child 3772 ec2babbd5698
permissions -rw-r--r--
removed Python2 modules
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# See COPYING file for copyrights details.


import hashlib


class ConnectorBase(object):

    chuncksize = 1024*1024

    def BlobFromFile(self, filepath, seed):
        s = hashlib.new('md5')
        s.update(seed)
        blobID = self.SeedBlob(seed)
        with open(filepath, "rb") as f:
            while blobID == s.digest():
                chunk = f.read(self.chuncksize)
                if len(chunk) == 0:
                    return blobID
                blobID = self.AppendChunkToBlob(chunk, blobID)
                s.update(chunk)
        raise IOError("Data corrupted during transfer or connection lost")