Class: Digestif::Hasher
- Inherits:
-
Object
- Object
- Digestif::Hasher
- Defined in:
- lib/digestif/hasher.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
- #digest ⇒ Object
-
#initialize(filename, options = CLI.default_options) ⇒ Hasher
constructor
A new instance of Hasher.
Constructor Details
Instance Attribute Details
#filename ⇒ Object
Returns the value of attribute filename.
9 10 11 |
# File 'lib/digestif/hasher.rb', line 9 def filename @filename end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/digestif/hasher.rb', line 9 def @options end |
Instance Method Details
#digest ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/digestif/hasher.rb', line 16 def digest hasher = Digest.const_get(.digest.to_s.upcase).new sample_count = 0 File.open(filename, 'rb') do |f| until f.eof hasher.update(f.read(.read_size)) f.seek(.seek_size, IO::SEEK_CUR) sample_count += 1 end end if .print_sample_count puts "#{filename}\t#{File.size(filename)}b\t#{sample_count} samples" end hasher.hexdigest end |