Module: Utils::MD5
- Defined in:
- lib/utils/md5.rb
Overview
MD5 module for computing MD5 hash digests of files.
This module provides functionality for calculating MD5 hash digests of files using the Digest::MD5 library. It offers a convenient interface for computing hashes while handling file reading in chunks to optimize memory usage during the hashing process.
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.
16 17 18 |
# File 'lib/utils/md5.rb', line 16 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.
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/utils/md5.rb', line 32 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 |