Hashes the contents of the file at the given path and returns the hash digest in hex form.

  If a hashlib message digest is not supplied a new sha1 message digest is used.
483677
def hash_file(path, digest=None):
  
  digest = digest or hashlib.sha1()
  with open(path, 'rb') as fd:
    s = fd.read(8192)
    while s:
      digest.update(s)
      s = fd.read(8192)
  return digest.hexdigest() if PY3 else digest.hexdigest().decode('utf-8')
501946
def _get_checksum(path):
    

    # md5 uses a 512-bit digest blocks, let's scale by defined block_size
    _md5 = hashlib.md5()
    chunk_size = 128 * _md5.block_size

    try:
        with open(path, 'rb') as _file:
            for chunk in iter(lambda: _file.read(chunk_size), ''):
                _md5.update(chunk)
        return _md5.hexdigest()

    except IOError:
        return None
383589
def compute_sha256(path):
    
    hasher = hashlib.sha256()
    with open(path, 'rb') as f:
        # 10MB chunks
        for chunk in iter(lambda: f.read(10 * 1024 * 1024), b''):
            hasher.update(chunk)
    return hasher.hexdigest()
1056080
def inspect_hash(path):
    "  "
    m = hashlib.sha256()
    with path.open("rb") as fp:
        while True:
            data = fp.read(HASH_BLOCK_SIZE)
            if not data:
                break
            m.update(data)

    return m.hexdigest()
750185
def _md5(path, blocksize=2 ** 20):
    """"""
    m = hashlib.md5()
    with open(path, 'rb') as f:
        while True:
            buf = f.read(blocksize)
            if not buf:
                break
            m.update(buf)
    return m.hexdigest()
980051
function calculateHash(filepath) {
    return new Promise((fulfill, reject) => {
        const file = fs.createReadStream(filepath);
        const hash = crypto.createHash('sha512');
        hash.setEncoding('hex');
        file.on('error', err => {
            reject(err);
        });
        file.on('end', () => {
            hash.end();
            fulfill(hash.read());
        });
        file.pipe(hash);
    });
}
1090473
def hash_file(filepath: str) -> str:
    """"""
    md5 = hashlib.md5()
    acc_hash(filepath, md5)
    return md5.hexdigest()
1175932
def get_md5_hash(file_path):
    
    checksum = hashlib.md5()
    with open(file_path, 'rb') as f:
        for chunk in iter(lambda: f.read(128 * checksum.block_size), b''):
            checksum.update(chunk)
    return checksum.hexdigest()
786326
def file_hash(path, hash_type='md5'):
    
    if os.path.exists(path):
        h = getattr(hashlib, hash_type)()
        with open(path, 'rb') as source:
            h.update(source.read())
        return h.hexdigest()
    else:
        return None
1300484
def get_hash(self, msg):
        '''
        
        '''
        msg = msg.encode('utf-8', 'replace')
        return hashlib.sha1(msg).hexdigest()
559651
def md5sum(path):
    

    if path is None or len(path) == 0 or not os.path.exists(path):
        return None

    try:
        with open(path + '.md5sum') as f:
            md5 = f.read()
            if len(md5) == 32:
                return md5
    # Unicode error is when user rename an image to .md5sum ....
    except (OSError, UnicodeDecodeError):
        pass

    try:
        m = hashlib.md5()
        with open(path, 'rb') as f:
            while True:
                buf = f.read(128)
                if not buf:
                    break
                m.update(buf)
        digest = m.hexdigest()
    except OSError as e:
        log.error("Can't create digest of %s: %s", path, str(e))
        return None

    try:
        with open('{}.md5sum'.format(path), 'w+') as f:
            f.write(digest)
    except OSError as e:
        log.error("Can't write digest of %s: %s", path, str(e))

    return digest
264305
def _md5(path: pathlib.PurePath):
        
        hash_ = hashlib.md5()
        with open(path, 'rb') as f:
            for chunk in iter(lambda: f.read(4096), b''):
                hash_.update(chunk)
        return hash_.hexdigest()
1271036
def _hash_of_file(path, algorithm):
    """"""
    with open(path, 'rb') as archive:
        hash = hashlib.new(algorithm)
        for chunk in read_chunks(archive):
            hash.update(chunk)
    return hash.hexdigest()
302827
def generate_hash_comment(file_path):
    
    with open(file_path, 'rb') as fp:
        hexdigest = hashlib.sha1(fp.read().strip()).hexdigest()
    return "# SHA1:{0}\n".format(hexdigest)
592152
def digest(type = :sha1)
      case type
      when :sha1
        Digest::SHA1.hexdigest(@bindata)
      when :sha256
        Digest::SHA256.hexdigest(@bindata)
      when :md5
        Digest::MD5.hexdigest(@bindata)
      else
        raise ArgumentError
      end
    end
976261
public static String sha1Hash(File file) throws IOException {
        try {
            DigestInputStream inputStream = new DigestInputStream(
                    new FileInputStream(file), MessageDigest.getInstance("SHA-1"));
            try {
                byte[] buffer = new byte[4098];
                while (inputStream.read(buffer) != -1) {
                    // Read the entire stream
                }
                return bytesToHex(inputStream.getMessageDigest().digest());
            } finally {
                inputStream.close();
            }
        } catch (NoSuchAlgorithmException ex) {
            throw new IllegalStateException(ex);
        }
    }
1203759
def hash_file(path, hashobj, conn=None):
    '''
    
    '''
    if os.path.isdir(path):
        return ''

    with salt.utils.files.fopen(path, 'r') as f:
        hashobj.update(salt.utils.stringutils.to_bytes(f.read()))
        return hashobj.hexdigest()