summaryrefslogtreecommitdiff
path: root/ext/digest/lib
diff options
context:
space:
mode:
Diffstat (limited to 'ext/digest/lib')
-rw-r--r--ext/digest/lib/digest.rb17
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb
index 1d1e420..a56d475 100644
--- a/ext/digest/lib/digest.rb
+++ b/ext/digest/lib/digest.rb
@@ -16,20 +16,27 @@ module Digest
raise NameError, "Digest class not found: Digest::#{name}"
end
- class Base
- # creates a digest object and read given file, _name_.
+ class ::Digest::Class
+ # creates a digest object and reads a given file, _name_.
#
# p Digest::SHA256.file("X11R6.8.2-src.tar.bz2").hexdigest
# # => "f02e3c85572dc9ad7cb77c2a638e3be24cc1b5bea9fdbb0b0299c9668475c534"
def self.file(name)
- digest = self.new
+ new.file(name)
+ end
+ end
+
+ module Instance
+ # updates the digest with the contents of a given file _name_ and
+ # returns self.
+ def file(name)
File.open(name, "rb") {|f|
buf = ""
while f.read(16384, buf)
- digest.update buf
+ update buf
end
}
- digest
+ self
end
end
end