From: rtilley Date: 2006-03-19T23:48:49+09:00 Subject: Re: safe way to calc md5 on very large files Robert Klemme wrote: > io.read will return nil at EOF so your test for positive length is > basically obsolete. Also, for reasons of error checking I'd place the > digest creation inside the block because then the digest is never > created if the file cannot be opened: > > md5 = File.open(file, 'rb') do |io| > dig = Digest::MD5.new > while (buf = io.read(4096)) > dig.update(buf) > end > dig > end Thank you Robert, Billy and others! Your suggestions have helped me to solve the problem.