summaryrefslogtreecommitdiff
path: root/ext/digest/lib/digest.rb
blob: 6ee1a0fbdfa5dc101c71123dc1c13a57dd5d690c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Digest
  autoload "MD5", "digest/md5"
  autoload "RMD160", "digest/rmd160"
  autoload "SHA1", "digest/sha1"
  autoload "SHA256", "digest/sha2"
  autoload "SHA384", "digest/sha2"
  autoload "SHA512", "digest/sha2"

  class Base
    # creates a digest object and read given file, _name_.
    # 
    #  p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
    #  # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
    def self.file(name)
      digest = self.new
      File.open(name, "rb") {|f|
        buf = ""
        while f.read(16384, buf)
          digest.update buf
        end
      }
      digest
    end
  end
end