From 93d8e716410bdf04346791e64b7446528371dfed Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 11 Jun 2014 12:05:19 -0500 Subject: [PATCH] Use Digest#file if it's available --- Library/Homebrew/extend/pathname.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index d0e77682ca..aca4997202 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -244,11 +244,15 @@ class Pathname %r[^#!\s*\S+] === open('r') { |f| f.read(1024) } end - def incremental_hash(hasher) - incr_hash = hasher.new - buf = "" - open('rb') { |f| incr_hash << buf while f.read(1024, buf) } - incr_hash.hexdigest + def incremental_hash(klass) + digest = klass.new + if digest.respond_to?(:file) + digest.file(self) + else + buf = "" + open("rb") { |f| digest << buf while f.read(1024, buf) } + end + digest.hexdigest end def sha1