Compute the MD5 hash for a given file.
979528
def get_digest(filename):
    """"""
    h = hashlib.md5()
    with open(filename, 'rb') as f:
        data = f.read(1 * MB)
        while data:
            h.update(data)
            data = f.read(1 * MB)
        return h.hexdigest()
525209
def md5_hash_file(fh):
    """"""
    md5 = hashlib.md5()
    while True:
        data = fh.read(8192)
        if not data:
            break
        md5.update(data)
    return md5.hexdigest()
700487
def _get_file_md5(filename):
    """"""
    md5_data = md5()
    with open(filename, 'rb') as f:
        for chunk in iter(lambda: f.read(128*md5_data.block_size), b''):
            md5_data.update(chunk)
    return md5_data.hexdigest()
290208
function hashFile(filename, callback) {

    var calledBack = false,
        md5sum = crypto.createHash('md5'),
        stream = fs.ReadStream(filename);

    stream.on('data', function (data) {
      md5sum.update(data);
    });

    stream.on('end', function () {
      var hash = md5sum.digest('hex');
      callback(null, hash);
    });

    stream.on('error', function(err) {
      handleResponse(err);
    });

    function handleResponse(err, hash) {
      if (calledBack) {
        return;
      }

      calledBack = true;
      callback(err, hash);
    }
  }
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()
272589
async function hash (file) {
  const filesize = await fileUtil.getFileSize(file)

  const chunkSize = 64 * 1024

  const firstBytesPromise = fileUtil.readBytes({
    file,
    chunkSize,
    start: 0
  })

  const lastBytesPromise = fileUtil.readBytes({
    file,
    chunkSize,
    start: filesize - chunkSize
  })

  const [ firstBytes, lastBytes ] = await Promise.all([firstBytesPromise, lastBytesPromise])

  return crypto
    .createHash('md5')
    .update(firstBytes)
    .update(lastBytes)
    .digest('hex')
}
1325206
private String calculateChecksum(File file) throws IOException {
		InputStream is = new FileInputStream(file);
		return DigestUtils.md5Hex(is);
	}
46506
def md5_for_file(f, block_size=2 ** 20):
    """"""

    md5 = hashlib.md5()
    try:
        # Guess that f is a FLO.
        f.seek(0)

        return md5_for_stream(f, block_size=block_size)

    except AttributeError:
        # Nope, not a FLO. Maybe string?

        file_name = f
        with open(file_name, 'rb') as f:
            return md5_for_file(f, block_size)
741824
def _md5sum(file_path):
    
    md5 = hashlib.md5()

    with open(file_path, "rb") as md5_file:
        while True:
            data = md5_file.read(1024 * 1024 * 4)
            if not data:
                break
            md5.update(data)

    return md5.digest()
10922
def md5(self):
        
        hash_ = hashlib.md5()
        with self.open("rb") as inf:
            block = inf.read(4096)
            while block:
                hash_.update(block)
                block = inf.read(4096)

        return hash_.hexdigest()
1131315
public static MD5Hash computeMd5ForFile(File dataFile) throws IOException {
    InputStream in = new FileInputStream(dataFile);
    try {
      MessageDigest digester = MD5Hash.getDigester();
      DigestInputStream dis = new DigestInputStream(in, digester);
      IOUtils.copyBytes(dis, new IOUtils.NullOutputStream(), 128*1024, false);
      
      return new MD5Hash(digester.digest());
    } finally {
      IOUtils.closeStream(in);
    }
  }
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
682930
def file_md5(self, file_name):
        """"""
        file_contents = self._read_file(file_name)
        file_contents = file_contents + "\n"  # Cisco IOS automatically adds this
        file_contents = file_contents.encode("UTF-8")
        return hashlib.md5(file_contents).hexdigest()
1036795
def validate_file(fpath, md5_hash):
    '''
    '''
    hasher = hashlib.md5()
    with open(fpath, 'rb') as f:
        buf = f.read()
        hasher.update(buf)
    if str(hasher.hexdigest()) == str(md5_hash):
        return True
    else:
        return False
1060068
public static String md5AsBase64(File file) throws FileNotFoundException, IOException {
        return Base64.encodeAsString(computeMD5Hash(file));
    }
1369643
def compute_gzip_md5(file_name):
    
    md5 = hashlib.md5()
    file_obj = gzip.open(file_name, 'rb')
    for chunk in iter(lambda: file_obj.read(8192), ''):
        md5.update(chunk)

    file_obj.close()
    return md5.hexdigest()
298407
def hash(filepath, method='sha1', buffer_size=65536):
    
    if method == 'sha1':
        hash_function = hashlib.sha1()
    elif method == 'md5':
        hash_function = hashlib.md5()
    else:
        raise NotImplementedError('Only md5 and sha1 hashes are known, but '
                                  ' \'{}\' was specified.'.format(method))

    with open(filepath, 'rb') as fp:
        while True:
            data = fp.read(buffer_size)
            if not data:
                break
            hash_function.update(data)
    return hash_function.hexdigest()