Open files in binary mode where appropriate

This commit is contained in:
Jack Nagel 2013-09-16 12:50:31 -05:00
parent 9b7786fc04
commit 84cbfb164e

View File

@ -174,7 +174,7 @@ class Pathname
# Get enough of the file to detect common file types # Get enough of the file to detect common file types
# POSIX tar magic has a 257 byte offset # POSIX tar magic has a 257 byte offset
# magic numbers stolen from /usr/share/file/magic/ # magic numbers stolen from /usr/share/file/magic/
case open { |f| f.read(262) } case open('rb') { |f| f.read(262) }
when /^PK\003\004/n then :zip when /^PK\003\004/n then :zip
when /^\037\213/n then :gzip when /^\037\213/n then :gzip
when /^BZh/n then :bzip2 when /^BZh/n then :bzip2
@ -200,7 +200,7 @@ class Pathname
def incremental_hash(hasher) def incremental_hash(hasher)
incr_hash = hasher.new incr_hash = hasher.new
buf = "" buf = ""
open('r') { |f| incr_hash << buf while f.read(1024, buf) } open('rb') { |f| incr_hash << buf while f.read(1024, buf) }
incr_hash.hexdigest incr_hash.hexdigest
end end