コード例 #1
0
ファイル: test_sync.py プロジェクト: B-Rich/gsync
def sha256sum(path):
    blocksize = 65536
    sha = hashlib.new("sha256")
    with open(path, "r+b") as f:
        for block in iter(lambda: f.read(blocksize), ""):
            sha.update(block)

    return sha.hexdigest()
コード例 #2
0
ファイル: test_sync.py プロジェクト: tortugajefe/gsync
def sha256sum(path):
    blocksize = 65536
    sha = hashlib.new("sha256")
    with open(path, "r+b") as f:
        for block in iter(lambda: f.read(blocksize), ""):
            sha.update(block)

    return sha.hexdigest()
コード例 #3
0
ファイル: __init__.py プロジェクト: quadrater/gsync
    def _md5_checksum(self, path):
        """Returns the checksum of the file"""

        if os.path.isdir(path):
            return None

        try:
            md5_gen = hashlib.new("md5")

            with open(path, "r") as fd:
                # Read the file in 1K chunks to avoid memory consumption
                while True:
                    chunk = fd.read(1024)
                    if not chunk:
                        break

                    md5_gen.update(chunk)

                return md5_gen.hexdigest()

        except Exception, ex: # pragma: no cover
            debug.exception(ex)
コード例 #4
0
    def _md5_checksum(self, path):
        """Returns the checksum of the file"""

        if os.path.isdir(path):
            return None

        try:
            md5_gen = hashlib.new("md5")

            with open(path, "r") as fd:
                # Read the file in 1K chunks to avoid memory consumption
                while True:
                    chunk = fd.read(1024)
                    if not chunk:
                        break

                    md5_gen.update(chunk)

                return md5_gen.hexdigest()

        except Exception, ex:  # pragma: no cover
            debug.exception(ex)