From: ara.t.howard@... Date: 2006-03-19T13:49:51+09:00 Subject: Re: safe way to calc md5 on very large files On Sun, 19 Mar 2006, Stephen Waits wrote: > rtilley wrote: >> I'm calculating md5 checksums on very large files (2 GB). This is a safe >> way to do so, right? Also... is the file closed when the block exits? I'm >> using 'rb' as this is used on Windows and Linux computers. >> >> md5 = Digest::MD5.new() >> File.open(file, 'rb').each {|line| md5.update(line)} >> > > Close.. try this.. > > require 'md5' > File.open(filename,'rb') { |f| MD5.hexdigest(f.read) } > > And yes, the file is closed with the block form of open. > > --Steve i think the OP has the right approach - note that an 'f.read' will consume 2GB. but the OP's code harp:~ > cat a.rb require 'digest/md5' md5 = Digest::MD5.new() and open(ARGV.shift, 'rb').each{|line| md5 << line} p md5.hexdigest will not. regards. -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama