aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorJake Good2010-03-27 10:41:24 -0500
committerAdam Vandenberg2010-03-30 09:24:12 -0700
commit404cc2b4b48f5a6d413dc5f3111fe3e714764c24 (patch)
tree1705ddf1813b6fcedca287f01fae02a529d81b5f /Library
parent2749c8cffca3da0f4fdb57b482ba116ed8ad67bc (diff)
downloadhomebrew-404cc2b4b48f5a6d413dc5f3111fe3e714764c24.tar.bz2
More hashing refactoring to work with byte chunks
Signed-off-by: Adam Vandenberg <flangy@gmail.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/extend/pathname.rb28
-rw-r--r--Library/Homebrew/formula.rb8
2 files changed, 22 insertions, 14 deletions
diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb
index d4fa6d92e..2c3d5a025 100644
--- a/Library/Homebrew/extend/pathname.rb
+++ b/Library/Homebrew/extend/pathname.rb
@@ -154,16 +154,30 @@ class Pathname
nil
end
-
- def md5
- require 'digest'
- incr_md5 = Digest::MD5.new
+
+ def incremental_hash(hasher)
+ incr_hash = hasher.new
self.open('r') do |f|
- f.each_line do |line|
- incr_md5 << line
+ while(buf = f.read(1024))
+ incr_hash << buf
end
end
- incr_md5.hexdigest
+ incr_hash.hexdigest
+ end
+
+ def md5
+ require 'digest/md5'
+ incremental_hash(Digest::MD5)
+ end
+
+ def sha1
+ require 'digest/sha1'
+ incremental_hash(Digest::SHA1)
+ end
+
+ def sha2
+ require 'digest/sha2'
+ incremental_hash(Digest::SHA2)
end
if '1.9' <= RUBY_VERSION
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 2605cd7a8..60865cacc 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -326,13 +326,7 @@ private
supplied=instance_variable_get("@#{type}")
type=type.to_s.upcase
hasher = Digest.const_get(type)
-
- # Most are MD5 and it should be efficient.
- if hasher == Digest::MD5
- hash = fn.md5
- else
- hash = hasher.hexdigest(fn.read)
- end
+ hash = fn.incremental_hash(hasher)
if supplied and not supplied.empty?
raise "#{type} mismatch\nExpected: #{hash}\nArchive: #{fn}" unless supplied.upcase == hash.upcase