Module: Utils::MD5
- Defined in:
- lib/utils/md5.rb
Class Attribute Summary collapse
-
.buffer_size ⇒ Integer
The buffer_size accessor method provides read and write access to the buffer_size instance variable.
Class Method Summary collapse
-
.md5(filename) ⇒ String
Computes the MD5 hash digest for a given file.
Class Attribute Details
.buffer_size ⇒ Integer
The buffer_size accessor method provides read and write access to the buffer_size instance variable.
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.
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 |