Module: Utils::MD5

Defined in:
lib/utils/md5.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.buffer_sizeInteger

The buffer_size accessor method provides read and write access to the buffer_size instance variable.

Returns:

  • (Integer)

    the current buffer size value



10
11
12
# File 'lib/utils/md5.rb', line 10

def buffer_size
  @buffer_size
end

Class Method Details

.md5(filename) ⇒ String

Computes the MD5 hash digest for a given file.

This method reads the entire contents of the specified file in binary mode and calculates its MD5 hash value. It uses a configurable buffer size for reading the file in chunks to optimize memory usage during the hashing process.

Parameters:

  • filename (String)

    the path to the file for which to compute the MD5 hash

Returns:

  • (String)

    the hexadecimal representation of the MD5 hash digest



26
27
28
29
30
31
32
33
34
35
# File 'lib/utils/md5.rb', line 26

def md5(filename)
  digest = Digest::MD5.new
  digest.reset
  File.open(filename, 'rb') do |f|
    until f.eof?
      digest << f.read(MD5.buffer_size)
    end
  end
  digest.hexdigest
end