From: Bill Kelly Date: 2006-03-19T14:45:37+09:00 Subject: Re: safe way to calc md5 on very large files From: "rtilley" > > 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)} Hi - does the file really contain text lines? Or is it a file full of binary data. If it's a binary file, there may be no guarantee the whole thing isn't one very long "line". In that case I'd recommend reading it in chunks. Untested: md5 = Digest::MD5.new() File.open(file, 'rb') do |io| while (buf = io.read(4096)) && buf.length > 0 md5.update(buf) end end Regards, Bill